Train Problem II

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

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
1
2
3
10
 
Sample Output
1
2
5
16796

Hint

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

 
Author
Ignatius.L
 

这题的意思就是和那个经典的出栈次序问题一模一样,就是卡特兰

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int a[][]; //大数卡特兰数
int b[]; //卡特兰数的长度 void Catalan(){ //求卡特兰数
int i,j,len,carry,tmp;
a[][]=b[]=;
len=;
for(i=;i<=;i++){
for(j=;j<len;j++) //乘法
a[i][j]=a[i-][j]*(*i-);
carry=;
for(j=;j<len;j++){ //处理相乘结果
tmp=carry+a[i][j];
a[i][j]=tmp%;
carry=tmp/;
}
while(carry){ //进位处理
a[i][len++]=carry%;
carry/=;
}
//carry=0;
for(j=len-;j>=;j--){ //除法
tmp=carry*+a[i][j];
a[i][j]=tmp/(i+);
carry=tmp%(i+);
}
while(!a[i][len-]) //高位零处理
len--;
b[i]=len;
}
} int main(){ //freopen("input.txt","r",stdin); int n;
Catalan();
while(~scanf("%d",&n)){
for(int i=b[n]-;i>=;i--)
printf("%d",a[n][i]);
printf("\n");
}
return ;
}

HDU 1023 Train Problem II (大数卡特兰数)的更多相关文章

  1. 1023 Train Problem II(卡特兰数)

    Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...

  2. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

  3. Train Problem II(卡特兰数 组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...

  4. Train Problem II(卡特兰数+大数乘除)

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

  6. HDU 1023 Train Problem II (卡特兰数,经典)

    题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...

  7. HDU 1023 Train Problem II( 大数卡特兰 )

    链接:传送门 题意:裸卡特兰数,但是必须用大数做 balabala:上交高精度模板题,增加一下熟悉度 /************************************************ ...

  8. Train Problem II (卡特兰数+大数问题)

    卡特兰数: Catalan数 原理: 令h(1)=1,h(0)=1,catalan数满足递归式: h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) ...

  9. HDOJ 1023 Train Problem II 卡特兰数

    火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...

随机推荐

  1. 【转载】springboot:如何优雅的使用mybatis

    这两天启动了一个新项目因为项目组成员一直都使用的是mybatis,虽然个人比较喜欢jpa这种极简的模式,但是为了项目保持统一性技术选型还是定了 mybatis.到网上找了一下关于spring boot ...

  2. Vs2013 坑爹的Target framework问题

    之前的一个项目是使用Vs2008来开发的,因为这段时间家里有事情所以只能跟经理协商在家里来做此项目,因为家里的VS是2013的所以在迁移时没有什么问题 但今天我更改一个类库的文件后重新生成解决方案结果 ...

  3. POI中setDefaultColumnWidth方法不起作用的原因

    sheet.setDefaultRowHeight((short) (2 * 256)); //设置默认行高,表示2个字符的高度 sheet.setDefaultColumnWidth(17);   ...

  4. Sublime Text 3 配置 PHPCS 插件

    Download php code sniffer addon via Package Control in ST3. Download The php-cs-fixer File From This ...

  5. 内建DNS服务器--BIND

    参考 BIND 官网:http://www.isc.org/downloads/bind/ 1.系统环境说明 [root@clsn6 ~]# cat /etc/redhat-release CentO ...

  6. HDS推出HUS中端阵列 文件、块和对象统一存储

    http://storage.chinabyte.com/86/12320086.shtml http://storage.chinabyte.com/134/12324134.shtml 日立数据系 ...

  7. 004-Go iris 接收post json数据

    package main import( "github.com/kataras/iris" "github.com/kataras/iris/middleware/lo ...

  8. 跟我学AngularJS:全局变量设置之value vs constant vs rootscope vs 服务[转]

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文要讲讲Angular中value vs. constant以及全局变量的设置 本教程 ...

  9. JAVA统计中文的个数

    尝试了一下 不错~ /** * 获取字符串的长度,中文占一个字符,英文数字占半个字符 * * @param value 指定的字符串 * @return 字符串的长度 */ public static ...

  10. python——从datetime模块探索python的数据架构

    问题出现于我试图向自建网页中加入实时时间开始. 我之前已经知道python中有有关事件和日期的模块datetime.以下导入datetime并作实验. >>> import date ...