ACM递归递推练习 Problem K

来源:互联网 发布:淘宝店店铺简介怎么写 编辑:程序博客网 时间:2024/05/21 11:15

//超级大水题

#include <iostream>
using namespace std;
int f(int x)
{
if(x<=3) return x;
return f(x-1)+f(x-2)+f(x-3);
}
int main(){
    int n;
while(cin>>n)
{
cout<<f(n)<<endl;
}
    return 0;
}

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]。
Sample Input
1
4
Sample Output
1
6
0 0
原创粉丝点击