i think this will do, using  DP
pre compute the sum[i,j] that contains sum of all the values from i to j

let M[i,j] is amount of money that can be made by selling the treats
then M[i,j] = max(a[i] + sum[i+1,j]+M[i+1,j], a[j]+sum[i,j-1],M[i,j-1])

i haven't checked your solution and don't know are u trying to do the same
correct me if i m wrong :)

Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to