Children’s Queue :(java 递推)

 1 import java.util.*;
 2 import java.math.*;
 3 import java.io.*;
 4 import java.lang.*;
 5 import java.text.*;
 6 class Main
 7 {
 8       public static void main(String []args)
 9       {
10           int n,i;
11           Scanner cin=new Scanner(System.in);
12           BigInteger a[]=new BigInteger[1010];
13           while(cin.hasNext())
14           {
15                 a[1]=BigInteger.valueOf(1);
16               a[2]=BigInteger.valueOf(2);
17               a[3]=BigInteger.valueOf(4);
18               a[4]=BigInteger.valueOf(7);
19               n=cin.nextInt();
20               for(i=5;i<=1000;i++)
21               {
22                   a[i]=a[i-1].add(a[i-2].add(a[i-4]));
23               }
24               System.out.println(a[n]);
25           }
26       }
27 }

 

posted @ 2012-08-22 12:41  疼痛落在指尖  阅读(185)  评论(0编辑  收藏  举报