文章
19
粉丝
0
获赞
147
访问
3.5k
递归:
#include<bits/stdc++.h>
using namespace std;
long long f[80];
int fib(int n){
if(n == 0 || n == 1) return 1;
if(n == 2) return 2;
return fib(n-1) + fib(n-2) + fib(n-3);
}
int main(){
int n;
while(cin >> n){
cout << fib(n) << endl;
}
return 0;
}
非递归:
#include<bits/stdc++.h>
using namespace std;
long long ll[75];
int main(){
int n;
ll[0] = 1;
ll[1] = 1;
ll[2] = 2;
while(cin >> n){
if(n == 0 || n == 1 || n == 2){
cout << ll[n] << endl;
&nb...
登录后发布评论
暂无评论,来抢沙发