#include <stdio.h>
long long a[55] = {0, 1, 2};
void fun()
{
for(int i = 3; i <= 50; i++)
a[i] = a[i - 1] + a[i - 2];
}
int main()
{
fun();
int N;
while(scanf("%d", &N) != EOF)
printf("%lld\n", a[N]);
return 0;
}
如图所示:
a
[
i
]
=
a
[
i
−
1
]
+
a
[
i
−
2
]
a[i] = a[i - 1] + a[i-2]
a[i]=a[i−1]+a[i−2]