HDU1023 Train Problem (卡特兰数)
2017-06-08 20:33
211 查看
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.
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.
#include<stdio.h> #include<string.h> int a[110][100];//大数卡特兰数 int b[110];//卡特兰数的长度 void Catalan()//求卡特兰数 { int i,j,k,len,tmp; a[1][0]=b[1]=1; len=1; for(i=2;i<=100;i++) { for(j=0;j<len;j++)//乘法 a[i][j]=a[i-1][j]*(4*i-2); k=0; for(j=0;j<len;j++)//处理相乘结果 { tmp=k+a[i][j]; a[i][j]=tmp%10; k=tmp/10; } while(k)//进位处理 { a[i][len++]=k%10; k/=10; } for(j=len-1;j>=0;j--)//除法 { tmp=k*10+a[i][j]; a[i][j]=tmp/(i+1); k=tmp%(i+1); } while(!a[i][len-1])//高位零处理 len--; b[i]=len; } } int main() { int n; Catalan(); while(~scanf("%d",&n)) { for(int i=b -1;i>=0;i--) printf("%d",a [i]); printf("\n"); } return 0; }
相关文章推荐
- 卡特兰数 hdu 1023||hdu1130||hdu1134||hdu||1131||hdu1131||hdu1133||。。。。。。
- hdu 1023 卡特兰数
- hdu 1023 Train Problem II 卡特兰数+java
- HDU 1023 Train Problem II (卡特兰数)
- 卡特兰数 Catalan数 hdu 1023
- HDU-1023 -Train Problem II(卡特兰数)
- HDU 1023 Train Problem II (卡特兰数)
- hdu 1023(大数+卡特兰数)
- HDU 1023 卡特兰数
- hdu 1023 卡特兰数《 大数》java
- hdu 1023 Train Problem II (卡特兰数)
- hdu 1023 1130 1134 卡特兰数 (中间有大数相除和大数相乘)
- HDU 1023 Train Problem II(卡特兰数)
- hdu 1023,catalan,卡特兰数
- HDU 1023卡特兰数 模板题
- HDU 1023 Traning Problem (2) 高精度卡特兰数
- HDU-1023 Train Problem II 卡特兰数(结合高精度乘除)
- 卡特兰数:poj 2084 Game of Connections+hdu 1023
- hdu 1023 卡特兰数+高精度
- hdu 1023 Train Problem II【卡特兰数】