#include
using namespace std;
int fillIt(int a,int b)
{
if(a<b)
return 1;
return fillIt(a-1,b)+fillIt(a-b,b);
}
int main() {
int t;
cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;
cout<<fillIt(a,b)<<endl;
}
return 0;
}
I wrote this and getting TLE. I optimised the code too
#include
using namespace std;
int fillIt(int a,int b)
{
if(a<b)
return 1;
int n = fillIt(a-1,b);
int m = fillIt(a-b,b);
return n+m;
}
int main() {
int t;
cin>>t;
while(t–)
{
int a,b;
cin>>a>>b;
cout<<fillIt(a,b)<<endl;
}
return 0;
}
But this still doesnt works.