您的位置:首页 > 其它

HDU 1023 高精度 卡特兰数

2014-02-17 00:34 387 查看

题目:


Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5139    Accepted Submission(s): 2771


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

Hint
The result will be very large, so you may not process it by 32-bit integers.

 
//h(n)=h(n-1)*(4*n-2)/(n+1)   n=i+1
卡特兰数的公式
//h(n)=h(n-1)*(4*n-2)/(n+1)   n=i+1
#include<stdio.h>
void main()
{
int a[100][101]={0},b[100];
int len=1,i,j,temp,n;
a[0][0]=1;
b[0]=1;
temp=0;
for(i=1;i<100;i++)
{
for(j=0;j<len;j++)
{
a[i][j]=a[i-1][j]*(4*i+2);
a[i][j]+=temp;
temp=a[i][j]/10;
a[i][j]%=10;
}
while(temp)
{
a[i][len++]=temp%10;
temp/=10;
}
temp=0;
for(j=len-
4000
1;j>=0;j--)
{
a[i][j]+=temp*10;
temp=a[i][j]%(i+2);
a[i][j]/=i+2;
}
j=len-1;
while(!a[i][j--])
len--;
b[i]=len;
}
while(scanf("%d",&n)!=EOF)
{
for(i=b[n-1]-1;i>=0;i--)
printf("%d",a[n-1][i]);
printf("\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: