I have gone through the previous discussions about the problem on Codechef but couldn’t really get the logic behind the dynamic programming solution. I would be grateful if you could explain the reason behind the solution along with the method for forming the equation of state. Code for the same is highly appreciated (in C++). Any advice on a general method to approach DP problems is highly appreciated.

Thanks for the code. I’ll go through it.

But can anyone suggest how can we develop these DP equations for such problems because the only thing I find on the internet is the Fibonacci example. It would be great if someone could post a link for a PDF which contains puzzles to be solved using pen and paper involving such DP equations.

The only way to be more good at Dynamic Programming is to try its problems more and more. For this, I found two good series of Dynamic programming

P.S: I am not related to any of these youtubers and neither advertising them. Just giving @utkarsh1729 sources where he can learn dynamic programming.

And keep solving problemsbased on dynamic programming on Codechef and any other site in which you do coding. Start from the easiest then go ahead, but practice as many problems you can.

Hope this was useful.

Thank you very much!!! The Codechef community is indeed very helpful.

Some resources which were very helpful for me while learning DP

https://codeforces.com/blog/entry/43256

https://www.iarcs.org.in/inoi/online-study-material/topics/dp.php