zoukankan      html  css  js  c++  java
  • HDU 2018 母牛的故事

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

    Problem Description
    有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
     
    Input
    输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。
    n=0表示输入数据的结束,不做处理。
     
    Output
    对于每个测试实例,输出在第n年的时候母牛的数量。
    每个输出占一行。
     
    Sample Input
    2
    4
    5
    0
     
    Sample Output
    2
    4
    6
     
    代码:
    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int maxn=1e5+10;
    
    int A(int x)
    {
        if(x<=4)
            return x;
        else
            return A(x-1)+A(x-3);
    }
    
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            if(n==0)
                break;
            else
                printf("%d
    ",A(n));
        }
        return 0;
    }
    

      

  • 相关阅读:
    CSU 1122
    CSU 1256
    CSU 1240
    HDU 1874
    CSU 1004
    Problem F CodeForces 16E
    Problem E CodeForces 237C
    Problem C FZU 1901
    12-30
    2016-12-29
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9321163.html
Copyright © 2011-2022 走看看