Tiling problem -II

What should be the correct logic for the question Tiling Problem -II.

Code-

#include
using namespace std;

int dp[100001]={0};

int findways(int n , int m)
{

if(dp[n]!=-1)
{

    return dp[n];
}
if(n<1)
    {
       
        dp[n]=0;
        return dp[n];


        }
if(n==m)

   { 
       dp[n]=2;
       return dp[n];
   }
if(n<m)
{ 
    dp[n]=1;
    return dp[n];
}


//recursive case

dp[n]= (findways(n-1,m)+ findways(n-m,m));

return dp[n];

}

int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
for(int i=0;i<100001;i++)
dp[i]=-1;

cout<<findways(n,m)%(1000000000+7)<<endl;


}

return 0;

}

Paste your code in cb.lk/ide ,then save it there and then send the link of code.

When you are calling recursion findways(n-1,m) + findways(n-m,m) , at this step integer overflow will occur. You have to take mod with 1e9+7 at every step.
Just add this.
dp[n]= ((findways(n-1,m)%1000000007+ findways(n-m,m))%1000000007)%1000000007;

ok i’ll try it right now

sir it got accepted. thanks a lot

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.