#include
using namespace std;
int count(int n)
{
if(n==1 || n==2)
{
return n;
}
int c1=count(n-1);
int c2=count(n-4);
return c1+c2;
}
int main() {
int n;
cin>>n;
cout<<count(n)<<endl;
return 0;
}
is my code correct?
Tiling recursion 4*1 size
You have to include case when n can be less than 1 because in recursive call of count(n-4) can will become -ve for n < 4.
#include
using namespace std;
int count(int n)
{
if(n<4)
{
return 1;
}
int c1=count(n-1);
int c2=count(n-4);
return c1+c2;
}
int main() {
int n;
cin>>n;
cout<<count(n)<<endl;
return 0;
}
now my correct for all test cases?
Yes it is correct, it will give correct output.