hdu 1023 Train Problem II 卡特兰数 java大数

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

 1 //package dhsjdhjkh;
 2 
 3 import java.util.*;
 4 import java.io.*;
 5 import java.math.BigInteger;
 6 
 7 public class Main {
 8 
 9     
10     public static void main(String[] args) 
11     {
12          int i;
13          BigInteger ans [] = new BigInteger[102];
14          
15          ans[0]= BigInteger.ONE;
16          ans[1]= BigInteger.ONE;
17          
18          for(i=2;i<=100;i++)
19              ans[i]=BigInteger.ZERO;
20 //         h(n)=h(n-1)*(4*n-2)/(n+1);
21          for(i=2;i<=100;i++){
22              ans[i] = ans[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
23              
24          }
25              
26 
27 
28          Scanner cin = new Scanner(System.in);
29          
30          while(cin.hasNext())//等价于!=EOF
31          {
32              int  n = cin.nextInt();//读入一个大整数
33              
34 //
35              System.out.println(ans[n]);
36              
37          }
38     
39     }
40 
41 }

 

posted @ 2014-05-06 15:02  galaxy77  阅读(187)  评论(0编辑  收藏  举报