posts - 99,  comments - 8,  trackbacks - 0
此题只要抓住一个突破口即可:第n 年的数目是前 n - 1 年的所有牛加上 n - 3 年前的小牛肯定会再产生一头
找好递归的出口是关键
#include <stdio.h>
#include 
<stdlib.h>


int main ()
{
    
int n;
    
int a[55];
    a[
1] = 1;
    a[
2] = 2;
    a[
3] = 3;
    
//a[4] = 4;
    for (int i = 4; i < 55; i ++)
    
{
        a[i] = a[i - 1] + a[i - 3];
    }
    
    
while ( scanf ("%d", &n) && n!= 0 )
    
{
          printf (
"%d\n", a[n]);
    }

    
return 0;
}

posted on 2010-08-13 16:36 雪黛依梦 阅读(525) 评论(0)  编辑 收藏 引用
<2026年10月>
日一二三四五六
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜