Hduoj1134【大数+几何】

/*Game of Connections 
Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
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
*/ 
#include<stdio.h>
#include<string.h>
int num[110][101], temp[101];
void big_add(int x)
{
	int i;
	for(i = 0; i < 100; ++i)
	{
		num[x][i] += temp[i];
		if(num[x][i] > 9)
		{
			num[x][i+1] += num[x][i] / 10;
			num[x][i] %= 10;
		}
	}
}

void big_mul(int x, int y)
{
	int i, j;
	memset(temp, 0, sizeof(temp));
	if(x == 1 || x == 0)
	{
		for(i = 0; i < 100; ++i)
		temp[i] = num[y][i];
		return ;
	}
	if(y == 1 || y == 0)
	{
		for(i = 0; i < 100; ++i)
		temp[i] = num[x][i];
		return ;
	}
	for(i = 0; i < 100; ++i)
	{
		for(j = 0; j < 100; ++j)
		temp[i+j] += (num[x][i] * num[y][j]);
	}
	for(i = 0; i < 100; ++i)
	if(temp[i] > 9)
	{
		temp[i+1] += temp[i]/10;
		temp[i]  %= 10;
	}
}
int main()
{
	int i, j, k, n;
	memset(num, 0, sizeof(num));
	num[0][0] = 1;
	num[1][0] = 1;
	num[2][0] = 2;
	num[3][0] = 5;
	for(i = 4; i <= 100; ++i)
	{
		for(j = 2; j <= 2*i; j += 2)//number
		{
			big_mul(i - (j/2), (j-2)/2);
			big_add(i);
		}
	}
	while(scanf("%d", &n) != EOF)
	{
		if(n == -1)
		break;
		if(n < 4)
		printf("%d\n", num[n][0]);
		else
		{
			for(i = 100; i >= 0; --i)
			{
				if(num[n][i] != 0)
				{
					for(j = i; j >= 0; j--)
					printf("%d", num[n][j]);
					printf("\n");
					break;
				}
			}
		}
	}
	return 0;
}


题意:给出一个数n,现在将1~2*n顺时针摆放围成一个圈,要求每2个数字之间进行连线,但要求线与线之间不得有交叉,求共有多少种组合。

思路:


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值