Here is my code

import java.util.*;
public class Main {
public static Scanner scn = new Scanner(System.in);
public static void main(String args[]) {
tilingProb();
}
public static void tilingProb(){
int t = scn.nextInt();
while(t–>0){
long n = scn.nextLong();
long m = scn.nextLong();
System.out.println(TP(n,m));
}
}

public static long TP(long n, long m){

    if(n>=1 && n<m) return 1; //only one way to place i.e vertically

    if(n== m) return 2;         // only 2 ways to place (all horizontal or all vertical)

    long count = 0;
    count = TP(n-1,m) + TP(n-m,m);          //n-1 for all verticals and n-m for all horizontals placed consecutively beneath 

return count;
}

}

It’s correct. You forgot to use mod though
you need to define mod as 10^9+7
then,
count =( TP(n-1,m)%mod + TP(n-m,m)%mod)%mod;

It’s still giving Run time error…I think I will have to apply dp . Thanks :slight_smile:

One more thing I had to ask. Should we use mod while we are dealing with long in case of Java as well?

It’s given in the question. so yes