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
Hint
The result will be very large, so you may not process it by 32-bit integers.
简单的卡特兰数问题。
卡特兰数介绍:
http://www.acmerblog.com/catalan-5196.html
由于Java里面有一个大数类,所以我就直接用了,有空我会把大数运算的处理补上
import java.math.BigInteger;
import java.util.*;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
while(in.hasNext()){
int n=in.nextInt();
BigInteger[] num=new BigInteger[105];
num[0]=num[1]=new BigInteger("1");
BigInteger a,b;
for (int i = 2; i <=n; i++) {
a=new BigInteger(Integer.toString(4*i-2));
b=new BigInteger(Integer.toString(i+1));
num[i]=num[i-1].multiply(a).divide(b);
}
System.out.println(num[n]);
}
}
}
主要是理解卡兰特数列一起应用问题:先构造数列,直接用即可,同斐波那契数列的应用,关键是抽象出数学模型