【JZOJ】【卡特兰数】【高精】WZK打雪仗

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值