题意:求入栈出栈的种数
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023
思路:卡特兰数列 f(n) = f(n-1)*(n*4-2)/(n-1)
注意点:Java类名必须为Main
以下为AC代码:
Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
12741193 | 2015-01-20 00:01:42 | Accepted | 1023 | 265MS | 9420K | 805 B | Java | luminous11 |
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner cin = new Scanner(System.in);
BigInteger[] num = new BigInteger[104];
num[0] = new BigInteger("1");
num[1] = new BigInteger("1");
num[2] = new BigInteger("2");
num[3] = new BigInteger("5");
for ( int i = 4; i < 101; i ++ ){
num[i] = new BigInteger("1");
int tmp = i * 4 - 2;
int j = 0;
BigInteger c = new BigInteger(((Integer)tmp).toString());
num[i] = num[i].multiply(num[i-1]);
num[i] = num[i].multiply(c);
int b = i + 1;
BigInteger d = new BigInteger(((Integer)b).toString());
num[i] = num[i].divide(d);
}
int k;
while ( cin.hasNext() ){
k = cin.nextInt();
System.out.println(num[k]);
}
}
}