TLE for test case except test case 3

here is my code: https://ide.codingblocks.com/s/245471
it is giving tle for all tet cases except test case 3.

hello @Garvit012
u need to use dynamic programming to pass all the testcases.

hello @aman212yadav sir
i have learned only recursion till now and this problem is from recursion section.

yeah i know this question is from recursion ,but to pass all test case u need to use dp.

leave this problem for now ,try again after learning dp

okay thanks a lot for your help