PROBLEM LINK :
Author: Himanshu Sharma
Tester: Vipul Ahuja
Editorialist: Himanshu Sharma
Easy DP, Recursion.
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[i]=max(DP[i-1],DP[i-1],DP[i-1],DP[i-1]); for j in range 1 to 3 DP[i][j]=DP[i-1][j]+v[i]; result=max(DP[N],DP);
Complexity of Above solution is O(N) in worst case.
Solution from a participated Team : Solution in cpp