Time Limit: 1000MS
|
|
Memory Limit: 30000K
|
Total Submissions: 8331
|
|
Accepted: 4141
|
Description
And, no two segments are allowed to intersect.
It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?
Input
You may assume that 1 <= n <= 100.
Output
Sample Input
2 3 -1
Sample Output
2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int max=100;
void mul(int a[],int b)
{///大數乘法
int i,jinwei=0;///進位
for(i=max-1;i>=0;i--)
{
jinwei+=b*a[i];
a[i]=jinwei%10000;
jinwei/=10000;
}
}
void div(int a[],int b)
{///大數除法
int i,jiewei=0;///借位
for(i=0;i<max;i++)
{
jiewei=jiewei*10000+a[i];
a[i]=jiewei/b;
jiewei%=b;
}
}
int main()
{
int n;
int i,j;
int a[101][101];
for(i=0;i<101;i++)
for(j=0;j<101;j++)
a[i][j]=0;
///初始化a[1]=1;
for(i=0;i<max-1;i++)
a[1][i]=0;
a[1][max-1]=1;
for(i=2;i<=100;i++)
{
memcpy(a[i],a[i-1],max*sizeof(int)); //將a[i-1]拷貝到a[i]
mul(a[i],4*i-2);
div(a[i],i+1);
}
while(scanf("%d",&n))
{
if(n==-1)
break;
for(i=0;i<max&&a[n][i]==0;i++);
printf("%d",a[n][i++]); ///輸出首位
for(;i<max;i++)
{
printf("%04d",a[n][i]);///輸出剩下的位數,數組中不足4位的在前邊補0
}
printf("\n");
}
return 0;
}