#2018 母牛的故事

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

万万没想到啊。。。居然要用递归,做不出来,可耻的ctrl + v了别人的答案。

分析能力都没了。

 1 #include<stdio.h>
 2 
 3 int f(int n)
 4 {
 5     if (n < 4)
 6     {
 7         return n;
 8     }
 9     else
10     {
11         return f(n - 1) + f(n - 3);
12     }
13 }
14 int main()
15 {
16     int n;
17     while (scanf("%d", &n) && n)
18     {
19         printf("%d
", f(n));
20     }
21     return 0;
22 }

当过了4年后,一年前的牛都会生,4年前的那个牛也开始生了。

原文地址:https://www.cnblogs.com/makejeffer/p/4779032.html