TIling Problem using Recursion

I’m getting TLE in all cases except 1 Please check if any correction.

import java.util.*;
public class Main {
public final static int mn =(int)Math.pow(10, 9)+7;
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();
int count=tilesCount(n, m);
System.out.println(count);
}
sc.close();
}

public static int tilesCount(int n, int m) {

	if(n>=1 && n<m) {
		return n-1;
	}
	if(n==m) {
		return 2;
	}
	int x=(tilesCount(n-1,m)%mn);
	int y=(tilesCount(n-m, m)%mn);
	return (x+y)%mn;
	

}

}

@Ritik488,
your approach is correct. Use DP to avoid TLE. Also use long instead if int.

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.