just use the following recurrence relation :
let arr[] be the array of integers and take an array a[]
a[i]=max(a[i-2], a]i-1], a[i-2]+arr[i]);
a[0]=arr[0];
a[1]=max(arr[0],arr[1]);
a[N-1] contains the final answer
@abhishek : the output for {3,5,7,10} should be 5+10=15 and not 13 as
pointed by u !! Correct me if I am wrong....
--
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.