加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

POJ 2084 大数+卡特兰数

发布时间:2020-12-14 03:18:09 所属栏目:大数据 来源:网络整理
导读:Game of Connections Time Limit: ?1000MS ? Memory Limit: ?30000K Total Submissions: ?8513 ? Accepted: ?4216 Description This is a small but ancient game. You are supposed to write down the numbers 1,2,3,. . .,2n - 1,2n consecutively in cloc
Game of Connections
Time Limit:?1000MS ? Memory Limit:?30000K
Total Submissions:?8513 ? Accepted:?4216

Description

This is a small but ancient game. You are supposed to write down the numbers 1,2,3,. . .,2n - 1,2n consecutively in clockwise order on the ground to form a circle,and then,to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another.?
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

Each line of the input file will be a single positive number n,except the last line,which is a number -1.?
You may assume that 1 <= n <= 100.

Output

For each n,print in a single line the number of ways to connect the 2n numbers into pairs.

Sample Input

2
3
-1

Sample Output

2

5

n最高到100..存不下 只能写个大数的了

#include<stdio.h>
#include<string.h>
#include<iostream>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int base= 10000;
const int maxn=200;
void mul(int num,int *w)
{
	int c=0;
	for(int i=maxn;i>=0;i--)
	{
		c+=w[i]*num;
		w[i]=c%base;
		c/=base;
	}
	return ;
}
void div(int num,int *w)
{
	int c=0;
	for(int i=0;i<=maxn;i++)
	{
		c=c*base+w[i];
		w[i]=c/num;
		c%=num;
	}
	return ;
}
int main()
{
	int n; 
	int a[111][maxn+1];
	memset(a,sizeof(a));
	a[0][maxn]=1;
	a[1][maxn]=1;
	for(int i=2;i<=100;i++)
	{
		memcpy(a[i],a[i-1],sizeof(a[i]));
		mul(4*i-2,a[i]);
		div(i+1,a[i]);	
	}
	while(scanf("%d",&n)!=EOF)
	{
		if(n==-1)
		break;
		int j=0;
		while(a[n][j]==0)
		j++;
		printf("%d",a[n][j]);
		for(int i=j+1;i<=maxn;i++)
		printf("%04d",a[n][i]);
		printf("n");
		
	}
 	return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读