列出前几种情况1,2,3,5,8,我们会发现这是一个斐波那契数列,关系式为f[i]=f[i-1]+f[i-2].
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<climits>
#define MAXA 55
using namespace std;
long long a[MAXA]={1,1,};
int main()
{
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
a[i] = a[i-1] + a[i-2];
}
printf("%lld",a[n]);
}