http://acm.hdu.edu.cn/showproblem.php?pid=1023
卡特兰数,用递推公式h(n)=h(n-1)*(4*n-2)/(n+1);
#include <iostream>
#include <cstdio>
using namespace std;
int a[101][101]={0};
int main()
{
int n,i,j,len,r,temp,t;
int b[101];
a[1][0] = 1;
len = 1;
b[1] = 1;
for(i=2;i<=100;i++)
{
t = i-1;
for(j=0;j<len;j++) //乘法
a[i][j] = a[i-1][j]*(4*t+2);
for(r=j=0;j<len;j++) //处理相乘结果
{
temp = a[i][j] + r;
a[i][j] = temp % 10;
r = temp / 10;
}
while(r) //进位处理
{
a[i][len++] = r % 10;
r /= 10;
}
for(j=len-1,r=0;j>=0;j--) //除法
{
temp = r*10 + a[i][j];
a[i][j] = temp/(t+2);
r = temp%(t+2);
}
while(!a[i][len-1]) //高位零处理
len --;
b[i] = len;
}
while(cin>>n)
{
for(j=b[n]-1;j>=0;j--)
printf("%d",a[n][j]);
printf("\n");
}
return 0;
}
java..
import java.io.*;
import java.util.*;
import java.math.*;
public class hdu1023 {//oj提交时类名必须是Main,否则ce
public static void main(String args[])throws IOException{
Scanner in=new Scanner(new InputStreamReader(System.in));
BigInteger[]ans=new BigInteger[105];
ans[0]=ans[1]=new BigInteger("1");
BigInteger tmp1,tmp2;
for(int i=2;i<105;i++){
tmp1=new BigInteger(Integer.toString(4*i-2));
tmp2=new BigInteger(Integer.toString(i+1));
ans[i]=(ans[i-1].multiply(tmp1)).divide(tmp2);
}
while(in.hasNext()){
int n=in.nextInt();
System.out.println(ans[n]);
}
}
}