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 10Sample Output
1
2
5
16796
Hint
#include<iostream>
using namespace std;
int a[110][101];//a[x][y],x表示第几个卡特兰数,a[y]则存储该数字,其中a[x][0],存储该数有几位。
void ktl();
int main()
{
ktl();
int n,i;
while(cin>>n)
{
for(i=a[n][0];i>0;i--)//乘除时是倒序
{
cout<<a[n][i];
}
cout<<endl;
}
}
void ktl()//先打表
{
int i,j,k,len,temp,num;
a[1][0]=1;
a[1][1]=1;
a[2][0]=1;
a[2][1]=2;
len=1;
for(i=3;i<=101;i++)
{
temp=0;//保存进位的数
for(j=1;j<=len;j++)
{
num=a[i-1][j]*(4*i-2)+temp;
temp=num/10;
a[i][j]=num%10;//进位处理
}
while(temp)//j>len时,temp进位可能不为0,故需要继续处理
{
a[i][++len]=temp%10;
temp/=10;
}
for(j=len;j>=1;j--)//除法
{
num=a[i][j]+temp*10;//大数同余
a[i][j]=num/(i+1);
temp=num%(i+1);
}
while(!a[i][len])//查找数的长度
{
len--;
}
a[i][0]=len;
}
}