HDU_1023_Train Problem II_卡特兰数

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7918    Accepted Submission(s): 4241


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
 
出栈问题。卡特兰数。
用java解决大数是多么的方便啊!!!
第一个java程序。
 
import java.util.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        BigInteger[] a=new BigInteger[105];
        a[0]=BigInteger.valueOf(1);
        a[1]=BigInteger.valueOf(1);
        for(int i=2;i<=100;i++)
            a[i]=BigInteger.valueOf(0);
        for(int i=2;i<=100;i++)
            for(int j=1;j<=i;j++)
                a[i]=a[i].add(a[j-1].multiply(a[i-j]));
        //System.out.println(a[10]);
        Scanner in =new Scanner(System.in);
        int n;
        while(in.hasNext())
        {
            n=in.nextInt();
            System.out.println(a[n]);
        }
    }

}
j
View Code
原文地址:https://www.cnblogs.com/jasonlixuetao/p/5531897.html