文章
37
粉丝
98
获赞
4
访问
24.0k
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
long long int fav[100] = { 0 };
long long fun( int n) {
if (fav[n] != 0) {//表明已算过并填入相应数组中了
return fav[n];
}
if (n == 0 || n == 1) {
fav[n] = 1;
return 1;
}
else if (n == 2) {
fav[n] = 2;
return 2;
}
fav[n] = fun(n - 1) + fun(n - 2) + fun(n - 3);
return fav[n];
}
int main()
{
int n;
while (cin >> n) {
cout << fun(n) << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发