Train Problem II
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
3
-
描述
-
As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.
-
输入
- The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file. 输出
-
For each test case, you should output how many ways that all the trains can get out of the railway.
(The result will be very large, so you may not process it by 32-bit integers.)
样例输入
-
1 2 3 10
样例输出
-
1 2 5
16796
-
思路:
-
卡特兰数的应用,以前都是用栈加深搜写的。。。没想到套个公式就行。。。
-
//train problem II //卡特兰数求法:Kn = [(n+2)*(n+3)*...*(2*n)] / [1*2*...*n] import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { BigInteger a, b, c; int n, i; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ a = BigInteger.ONE; b = BigInteger.ONE; c = BigInteger.ONE; n = sc.nextInt(); for(i = 1; i <= n; i++){ a = a.multiply(BigInteger.valueOf(i)); } for(i = n+2; i <= 2*n; i++) { b = b.multiply(BigInteger.valueOf(i)); } c = b.divide(a); System.out.println(c); } } }