1.走楼梯(stairs)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d53a93208cf2997795a209dc25ac9e80.png)
#include <bits/stdc++.h>
using namespace std;
int climbStairs(int n)
{
if(n < 1)
return 0;
if(n == 1)
return 1;
if(n == 2)
return 2;
return climbStairs(n-1) + climbStairs(n-2);
}
int main()
{
int n;
cin>> n;
cout<< climbStairs(n)<< endl;
return 0;
}
- 参考文章:https://blog.csdn.net/li1376417539/article/details/90673110
- https://blog.csdn.net/ajiangfan/article/details/52822411
2. 兔子繁殖(rabbit)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c8e76ad9f3ac2ae23114babd670236d2.png)
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int a[105],b[105];
int n,i,m;
scanf("%d",&n);
a[1] = 0;
b[1] = 1;
a[2] = 1;
b[2] = 0;
for(i = 3;i <= n;i++)
{
b[i] = a[i - 1];
a[i] = a[i - 1] + b[i - 1];
}
m = b[n] + a[n];
printf("%d",m);
return