D e s c r i p t i o n Description Description
按顺序排成的一个有2n个点的圆,问有多少种方法,连接n条边(两个点之间相连),每个点只能连一条边,问有多少种方案使得n条边互不相交
I n p u t Input Input
一行一个整数N。
O u t p u t Output Output
一行一个整数,为方案总数。
无解输出“No Solution”,注意大小写及之间的一个空格,不包括引号。
因为方案数可能很大,所以你懂的…
S a m p l e Sample Sample I n p u t Input Input
5
S a m p l e Sample Sample O u t p u t Output Output
42
解释:
一种可行的方案如下:
H i n t Hint Hint
【数据范围】
对于30%数据: n<=30。
对于100%数据: n<=100。
T r a i n Train Train o f of of T h o u g h t Thought Thought
这一道题讲起来比较麻烦,先看懂卡特兰数,知道其推导公式之后加上高精即可AC
C o d e Code Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int f[125][125][100];
int n;
void add(int *A,int *X,int *Y)
{
int l=0;
for(int i=1;i<=100;++i)
{
l=X[i]+Y[i]+l;
A[i]=l%10;
l/=10;
}
return;
}//高精
void write(int *X)
{
int l=101;
while(!X[--l] && l>1);
printf("%d",X[l]);
while(--l)printf("%d",X[l]);
return;
}
int main()
{
//freopen("war.in","r",stdin);
//freopen("war.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;++i)
f[1][i][1]=i;
for(int i=2;i<=n;++i)
for(int j=i;j<=n;++j)
add(f[i][j],f[i-1][j],f[i][j-1]);//卡特兰数的推导公式
write(f[n][n]);
return 0;
}