前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU 1023 高精度 卡特兰数

HDU 1023 高精度 卡特兰数

作者头像
csxiaoyao
发布2019-02-18 18:02:12
5060
发布2019-02-18 18:02:12
举报
文章被收录于专栏:csxiaoyao

题目:

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5139    Accepted Submission(s): 2771

Problem Description

As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.

Input

The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.

Output

For each test case, you should output how many ways that all the trains can get out of the railway.

Sample Input

代码语言:javascript
复制

1 2 3 10

Sample Output

代码语言:javascript
复制

1 2 5 16796

Hint

The result will be very large, so you may not process it by 32-bit integers.

代码语言:javascript
复制
//h(n)=h(n-1)*(4*n-2)/(n+1)   n=i+1

卡特兰数的公式

代码语言:javascript
复制
//h(n)=h(n-1)*(4*n-2)/(n+1)   n=i+1
#include<stdio.h>
void main()
{
	int a[100][101]={0},b[100];
	int len=1,i,j,temp,n;
	a[0][0]=1;
	b[0]=1;
	temp=0;
	for(i=1;i<100;i++)
	{
		for(j=0;j<len;j++)
		{
			a[i][j]=a[i-1][j]*(4*i+2);
			a[i][j]+=temp;
			temp=a[i][j]/10;
			a[i][j]%=10;
		}
		while(temp)
		{
			a[i][len++]=temp%10;
			temp/=10;
		}
		temp=0;
		for(j=len-1;j>=0;j--)
		{
			a[i][j]+=temp*10;
			temp=a[i][j]%(i+2);
			a[i][j]/=i+2;
		}
		j=len-1;
		while(!a[i][j--])
			len--;
		b[i]=len;
	}
	while(scanf("%d",&n)!=EOF)
	{
		for(i=b[n-1]-1;i>=0;i--)
			printf("%d",a[n-1][i]);
		printf("\n");
	}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014年02月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目:
  • Train Problem II
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档