public static long tileP(int n,int m,long dp[]){
if(n <= 0)
return 0;
if(n >=1 && n < m)
return 1;
if(n == m)
return 2;
if(dp[n]!=0)
return dp[n];
dp[n] = tileP(n-1,m,dp) + tileP(n-m,m,dp);
return dp[n];
}
public static long tileP(int n,int m,long dp[]){
if(n <= 0)
return 0;
if(n >=1 && n < m)
return 1;
if(n == m)
return 2;
if(dp[n]!=0)
return dp[n];
dp[n] = tileP(n-1,m,dp) + tileP(n-m,m,dp);
return dp[n];
}
@S18ML0001
hello ujjwal,

a)u need to take modulo of ur answer
b) also use this property -> (a+b)%mod=(a%mod+b%mod)%mod
public static long tileP(int n,int m,long dp[]){
if(n <= 0)
return 0;
if(n >=1 && n < m)
return 1;
if(n == m)
return 2;
if(dp[n]!=0)
return dp[n];
dp[n] = tileP(n-1,m,dp) + tileP(n-m,m,dp);
return dp[n];
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int m = sc.nextInt();
long ans = tileP(n,m,new long[n+1])%(1000000007);
System.out.println(ans);
}
}
Here is my whole code. There is some error that i cannot figure out.
here u need to use modulo property
dp[n]= ( tileP(n-1,m,dp) % mod + tileP(n-m,m,dp) % mod ) % mod;