Here's my code https://ideone.com/78vdAO

its showing time limit exceeded

Can I do it with recursion without DP since I haven’t done it yet

Hey, yes you can solve this problem with recursion without DP but that will result into many unnecessary duplicate calls which is not good. If you carefully observe the sequence for this problem it results in a fibonacci sequence.Also, It is given in the problem that your ans value can be large so take ans % 1000000007, this will help you in removing TLE.

Hi! To find out what I can do, say @discobot display help.