点击获取原题链接
们--加强斐波那契
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
对于斐波那契数列想必各位已经见过了。这里给出一个加强版。
F[i] = i (i <= 3);
F[i] = F[i-1] + F[i-2] + F[i-3](i >= 4);
Input
多组输入。每组输入一个整数n (1<= n && n <= 30)。
Output
每组数据输出一个整数,代表F[n]。
Example Input
1
4
Example Outpu
1
6
Hint
Author
#include <bits/stdc++.h>
using namespace std;
long long a[
35];
int main()
{
a[
1]=
1;
a[
2]=
2;
a[
3]=
3;
for(
int i=
4;i<=
35;i++)
{
a[i]=a[i-
1]+a[i-
2]+a[i-
3];
}
int n;
while(
cin>>n)
{
cout<<a[n]<<endl;
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-4949.html