Train Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7977 Accepted Submission(s): 4278
Problem Description
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.
Input
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.
Output
For each test case, you should output how many ways that all the trains can get out of the railway.
Sample Input
1 2 3 10
Sample Output
1 2 5 16796HintThe result will be very large, so you may not process it by 32-bit integers.
Author
Ignatius.L
Recommend
import java.math.BigInteger;
import java.util.Scanner;
/*
卡特兰数:
ans=C[2*n][n]/(n+1);
因为C[][] 到了32左右就爆int了
此题n达到100 直接用大数
*/
public class Main {
final static int maxn=100;
static BigInteger[][] C=new BigInteger[2*maxn+10][2*maxn+10];
public static void pre()
{
C[0][0]=BigInteger.ONE;
for(int i=1;i<=2*maxn;i++)
{
C[i][0]=C[i][i]=BigInteger.ONE;
for(int j=1;j<i;j++)
{
C[i][j]=C[i-1][j-1].add(C[i-1][j]);
}
}
}
public static void main(String args[])
{
pre();
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt())
{
int n=sc.nextInt();
BigInteger ans=C[2*n][n].divide(BigInteger.valueOf(n+1) );
System.out.println(ans);
}
}
}