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

特殊函数卡特兰数 hdu 1134

发布时间:2020-12-14 02:42:10 所属栏目:大数据 来源:网络整理
导读:Game of Connections Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3352????Accepted Submission(s): 1910 Problem Description This is a small but ancient game. You are supposed to wri

Game of Connections

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3352????Accepted Submission(s): 1910


Problem 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
?

Source
Asia 2004,Shanghai (Mainland China),Preliminary?
题目大意:2n个连线,不能相交,求最多有多少种可能的握手方法?
考察知识点:大数,卡特兰数
//考察知识点:卡特兰数 && 大数。
/*
h(1)=1,h(0)=1;h(n)=((4*n-2)/(n+1))*h(n-1);(其中n>=2) 
*/ 
#include<stdio.h>
#include<string.h>
#define inf 110
int a[inf][inf];
int i,j,temp,len,n;
void f()
{
	temp=0;len=1;
	memset(a,sizeof(a));
	a[1][0]=1;
	for(i=2;i<=100;++i)
	{
		for(j=0;j<len;++j)
		{
			a[i][j]=a[i-1][j]*(4*i-2);
		}
		for(j=0;j<len;++j)
		{
			temp+=a[i][j];
			a[i][j]=temp%10;
			temp/=10;
		}
		while(temp)
		{
			a[i][len++]=temp%10;
			temp/=10;
		}
		//len--;
		for(j=len-1;j>=0;--j)
		{
			temp=temp*10+a[i][j];
			a[i][j]=temp/(i+1);
			temp%=i+1;
		}
		while(!a[i][len-1])
		len--;
	}
}
int main()
{
	f();
	while(~scanf("%d",&n),n!=-1)
	{
		for(i=inf-1;i>=0&&!a[n][i];--i);
		for(;i>=0;--i)
		printf("%d",a[n][i]);
		puts("");
	}
	return 0;
} 
 

(编辑:李大同)

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

    推荐文章
      热点阅读