Tilling problem(recursion)

#include
using namespace std;
int tiling(int n,int m){
if(n<m){
return tiling(m,n);
}
if(n==1||n==m){
return n;
}
int ans=tiling(n-1,m)+tiling(n-m,m);
return ans;
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
int n,m;
cin>>n>>m;
cout<<tiling(n,m)<<endl;
}
}
whats wrong in this code

@tishya_goyal
hello Tishya,
ur base cases are not correct.

if n<m :
then return 1.

if n==m
then return 2

there is a issue of time limit exceed …how i can resolve it?

u need to use dynamic programming to resolve tle issue.

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.