链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023
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
本题是一道卡特兰数的简单题,但是写大数写了一下午,因为一个小地方的错误一直在悲剧。
卡特兰数:
递归式:h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) );
1 #include <stdio.h>
2 int a[105][100];
3 void ktl( )
4 {
5 int i, j, yu, len;
6 a[2][0]=1;
7 a[1][1]=1;
8 a[1][0]=1;
9 len=1, a[2][1]=2;
10 for( i=3; i<101; ++i )
11 {
12 yu=0;
13 for( j=1; j<=len; ++j )
14 {
15 //int t=( a[i-1][j]+yu) * ( 4*i-2 ); wa了一下午
16 int t=( a[i-1][j]) * ( 4*i-2 )+yu;
17 yu=t/10;
18 a[i][j]=t%10;
19 }
20 while( yu )
21 {
22 a[i][++len]=yu%10;
23 yu/=10;
24 }
25 for( j=len; j>=1; --j )
26 {
27 int t=a[i][j]+yu*10;
28 a[i][j]=t/( i+1 );
29 yu= t%(i+1);
30 }
31 while( !a[i][len] )
32 {
33 len--;
34 }
35 a[i][0]=len;
36 }
37 }
38 int main( )
39 {
40 ktl( );
41 int n;
42 while( scanf( "%d", &n ) != EOF )
43 {
44 for( int i=a[n][0]; i>0; --i )
45 {
46 printf( "%d", a[n][i] );
47 }
48 puts( "" );
49 }
50 }