递归算法——农夫养牛之动归

 1 /**
 2  * Created by Administrator on 14-5-15.
 3  */
 4 public class NewCow_DP {
 5     public static void main(String[] args){
 6         int[] cows=new int[31];
 7         cows[1]=1;
 8         cows[2]=1;
 9         cows[3]=2;
10         for(int i=4;i<=30;i++){
11             cows[i]=cows[i-1]+cows[i-3];
12         }
13         for(int i=1;i<=30;i++)
14             System.out.println(i+"年后有牛:"+cows[i]);
15     }
16 }

 

posted @ 2014-07-14 09:56  冥草有心  阅读(251)  评论(0编辑  收藏  举报