Not getting right output in Dynamic programming

I was trying to solve this problem of dynamic programming using memoization:

I wrote down the plain recursive solution to this question, and then I tried to do it using recursion.

But the code I tried to write using memoization is not working.

This is the link to the code.

Please help me find out why my code is not working correctly

https://ide.codingblocks.com/s/389997 u can refer this… here i have explained both bottom up and top down approaches

Sir I had a query, that you have written this in the bottom up approach:

if(i%3 == 0) op1 = dp[i/3];

    if(i%2 == 0) op2 = dp[i/2];

    op3 = dp[i-1];

Why did we call dp[i/3] recursively first, could we have called op3=dp[i-1] first or op2=dp[i/2] first?

yes… u can do that in any order… that doesn’t matter

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.