I am not too good in DP and recursions. But I have tried to make this code. Some of the example inputs are running correctly but most are wrong. I am not able to figure out what’s wrong with the logic.
It is difficult to read code that is not commented, or otherwise explained.
Here is some code that works, by the way.
Your code will give wrong answer for the following test case:
3 2 1 1 2 3 1 3 2 1
your answer : 14
expected : 15
You haven’t considered a possibility fee[i]+fee[i-1]+best[i-4] for i>=4