PROBLEM LINK :Contest
PREREQUISITES:Easy DP, Recursion.
PROBLEM:chefs mom has collection of N chocolates. Each chocolate has different taste value. Mom has some rules, chef can eat atmost 3 chocolates in a row, to eat next chocolates he must skip atleast 1 chocolate. Chef wants to get maximum possible taste value. Find out maximum possible taste value chef can get.
The above problem is standard DP problem.
Let DP : 2d vector for storing intermediate values.
And let V: vector of elements.
DP=DP=DP=DP=V; for i in range 2 to N DP*=max(DP[i-1],DP[i-1],DP[i-1],DP[i-1]); for j in range 1 to 3 DP*[j]=DP[i-1][j]+v*; result=max(DP[N],DP);
Complexity of Above solution is O(N) in worst case.