您的位置:首页 > 其它

【HDOJ】1134 Game of Connections

2014-12-26 11:16 288 查看
Catlan数。

/* 1134 */
import java.util.Scanner;
import java.math.BigInteger;

/*
Catalan:
(1) h(n) = h(n-1) * (4*n-2) / (n+1)
(2) h(n) = C(2n, n) / (n+1)
(3) h(n) = C(2n, n) - C(2n, n+1)
*/

public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
BigInteger[] bi = new BigInteger[MAXN];
bi[1] = BigInteger.ONE;
bi[2] = BigInteger.valueOf(2);
for (int i=3; i<MAXN; ++i) {
BigInteger x = BigInteger.valueOf(4*i-2);
BigInteger y = BigInteger.valueOf(i+1);
bi[i] = bi[i-1].multiply(x).divide(y);
}
int n;
while (cin.hasNext()) {
n = cin.nextInt();
if (n == -1)
break;
System.out.println(bi
);
}
}

public static final int MAXN = 101;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: