Train Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5752 Accepted Submission(s): 3115
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 16796卡特兰数的应用import java.io.InputStreamReader; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner in=new Scanner(System.in); BigDecimal[] a=new BigDecimal[105]; BigDecimal b,c,d,e; a[1]=new BigDecimal(1); for(int i=2;i<101;i++) { b=new BigDecimal(4*i-2); c=new BigDecimal(i+1); d=a[i-1].multiply(b); a[i]=d.divide(c); } while(in.hasNext()) { int x=in.nextInt(); System.out.println(a[x]); } } }