原题:
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.
题意:
给出一个数,求他的卡特兰数,及出栈顺序的种数。
题解:
卡特兰数的公式为F(n)=c(2n,n)/(n+1),然而因为要求大数的卡特兰数,所以必须用数组来储存(大数真的无力),wa了好久改改补补才过掉,难点就在公式的大数处理上
代码:AC
#include<stdio.h>
#include<string.h>
int h[101][121];
int main()
{
int i,j,k,l,n;
memset(h, 0, sizeof(h));
h[0][1]=1;
h[1][1]=1;
for(i = 2; i <= 100; ++i)
{
for(j = 0; j < i; ++j)
for(k = 1; k < 60; ++k)
for(l = 1; l < 60; ++l)
h[i][k + l - 1] += h[j][k] * h[i - j - 1][l];
for(j = 1; j < 60; ++j)
{
h[i][j + 1] += h[i][j] / 10;
h[i][j] %= 10;
}
}
while(scanf("%d", &n) != EOF)
{
i=60;
while( h[n][--i] == 0 )
;
for(j = i; j > 0; --j)
printf("%d", h[n][j]);
printf("\n");
}
return 0;
}