In some Dynamic Programming Problems, I am able to code the recursive solution but I find it hard to convert it into Top-Down DP or Memoization. For example :- This is a problem from yesterday's Codechef Starters Contest:- Problem Link
Below is my Recursive Code to the problem:-
My Code
It would be helpful if someone could suggest me some ideas on how to do so.