This is not done using brute force why is it still giving tle except for one test case

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

int tiling(int n,int m){
if(n==m)
return 2;
if(1<=n&&n<m)
return 1;

return (tiling(n-m,m)%mod+tiling(n-1,m)%mod)%mod;

}
int main() {
int t;
cin>>t;

while(t--){
    int n,m;
    cin>>n>>m;
    cout<<tiling(n,m)%mod<<endl;
}

}

hello @Kshitij-Taneja-2315806971864318
your solution is based on recursion and it has exponential time complexity. that is the reason why it is working for small test cases but giving tle for larger one.

use dynamic programming/memoisation to improve it time complexity

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.