HDU 2018 母牛的故事

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2018

递推,每年生的牛 = 上一年的所有母牛数 + 4年前所有母牛数(因为每4年母牛长大,大母牛会生小母牛) f(n) = f(n-1) + f(n-3)

#include <iostream>

using namespace std;

int main()
{
    int f[56]= {0,1,2,3,4,6};
    for(int i=6; i<56; i++)
    {
            f[i]=f[i-1]+f[i-3];
    }
    int n;
    while(cin>>n&&n)
    {
        cout<<f[n]<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/destino74/p/3332021.html