Getting TLE in some test cases

TLE in 4 test cases. I used the simple recursion method . Code here https://ide.codingblocks.com/s/200882 .I also check some forums, its said we need to use DP. Can’t this be solved solely using recursion?

No…since the constraints are large enough, you have to use DP in order to pass all the test cases.

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.