题解:卡特兰数的几何意义,所以答案就是卡特兰数的两倍
#include <cstdio>
#include <iostream>
using namespace std;
#define base 10000
#define len 100
void multiply(int a[],int max,int b){
int i,array=0;
for(i=max-1;i>=0;i--){
array+=b*a[i];
a[i]=array%base;
array/=base;
}
}
void divide(int a[],int max,int b){
int i,div=0;
for(i=0;i<max;i++){
div=div*base+a[i];
a[i]=div/b;
div%=b;
}
}
int main(){
int n,i,a[101][len];
memset(a[1],0,len*sizeof(int));
for(i=2,a[1][len-1]=2;i<101;i++){
memcpy(a[i],a[i-1],len*sizeof(int));
multiply(a[i],len,4*i-2);
divide(a[i],len,i+1);
}
int t=1;
while(scanf("%d",&n),n!=-1){
printf("%d %d ",t++,n);
for(i=0;i<len&&a[n][i]==0;i++);
printf("%d",a[n][i++]);
for(;i<len;i++)printf("%04d",a[n][i]);
printf("\n");
}return 0;
}