hdu Game of Connections

时间:2014-08-05 11:00:09   收藏:0   阅读:307

卡特兰数 递推公式:h(n)=h(n-1)*(4*n-2)/(n+1);

bubuko.com,布布扣
 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5 
 6     public static void main(String args[]) {
 7         Scanner cin = new Scanner(System.in);
 8         BigInteger[] c = new BigInteger[101];
 9         c[1] = BigInteger.valueOf(1);
10         c[2] = BigInteger.valueOf(2);
11         for (int i = 3; i <= 100; i++) {
12             BigInteger x1 = BigInteger.valueOf(4*i-2);
13             BigInteger x2 = BigInteger.valueOf(i+1);
14             c[i]=c[i-1].multiply(x1).divide(x2);
15         }
16     
17         while (cin.hasNext()) {
18             int N = cin.nextInt();
19             if (N==-1)
20                 break;
21             else
22                 System.out.println(c[N]);
23         }
24     }
25 }
View Code

 

hdu Game of Connections,布布扣,bubuko.com

原文:http://www.cnblogs.com/fanminghui/p/3891629.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!