💡 Tilling Problem - II (what's wrong)

why this not work can you find the fault plz.


#include<iostream>
#include<cstring>
#define mod 1000000007
using namespace std;

long tileing(long *dp, long n, long &m){
	if(dp[n]!=-1)
		return dp[n];
	long ans = tileing(dp, n-1, m)%mod;
	long ans2 = tileing(dp, n-m, m)%mod;
	dp[n] = (ans + ans2)%mod;
	return dp[n];
}

int main() {
	long t,m,n;
	cin>>t;
	while(t--){
		cin>>n>>m;
		// n=20;
		// m=4;
		if(n<m){
			cout<<"1\n";
			continue;
		}
		if(n==m){
			cout<<"2\n";
			continue;
		}
		long dp[n];
		memset(dp,-1,sizeof(dp));
		dp[0] = 0;
		for(int i=1;i<m;i++)
			dp[i]=1;
		dp[m]=2;
		cout << tileing(dp, n, m)<<endl;
		// for(int i=0;i<10;i++)
			// cout<<dp[i]<<" ";

	}
	return 0;
}

calling n-m without checking if its possible to use that or not

i got it
i create array of size n than i access nth index
array must be n+1 size

Oh well
great!
Good luck

1 Like

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.