Code only passing for the 4th test case(Tilling 2 problem)

Could you check my code and tell me where is it incorrect

Could anyone please review my code and tell me the error.

Since constraints are large, plz use long long int , take a[0] = 1;
a[1] = 1;
and use this loop condition only to determine values for dp array

for(int i=2;i<=n;i++)

I am using this loop only but I’ve split it into two parts

  1. i=2 to i<m in this loop n<m hence all values will be 1
  2. i=m+1 to i<=n here I am using a[i] = a[i-1] + a[i-m]
    and I have set the value of a[m] = 2 which means when n=m

I think the problem is when I do modulo with 10^9 + 7

Dry running this code with small inputs gives the correct answer but there is something wrong with larger inputs

TA’s? could you clear the doubt


I have modified your code a little bit. If you didnt understood the modifications, plz let me know…

Understood the changes, the code passed all test cases .
Thank you

I didnt understand the logic, could you please explain