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. 2017 年度码云新增项目排行榜 TOP 50,为它们打“call”

    2017 年度码云新增项目排行榜 TOP 50 正式出炉 !2017 结束了,我们来关注一下这一年里码云上新增的最热门的开源项目吧.此榜单根据 2017 年在码云上新增开源项目的 Watch.Star ...

  2. 红米1线刷救砖教程V5版(移动联通适用,线刷包永久有效)

    红米1线刷救砖教程V5版(移动联通适用,线刷包永久有效) 原文来自:http://www.miui.com/thread-1890972-1-1.html?mobile=2 ,加了些自己的经验. (我 ...

  3. GLFW_KEY_KP_ADD和GLFW_KEY_KP_SUBTRACT

      这两个键的代码分别为: GLFW_KEY_KP_ADD(334) GLFW_KEY_KP_SUBTRACT(333)   对应的是键盘右侧数字面板上的+ -键.

  4. [Canvas]人物型英雄出现(前作仅为箭头)

    源码点此下载,用浏览器打开index.html观看. 代码: <!DOCTYPE html> <html lang="utf-8"> <meta ht ...

  5. .NET 托管、非托管、本地:这些代码有什么区别?

    http://www.codeguru.com/Csharp/.NET/cpp_managed/article.php/c4871 本文内容 什么是托管代码? 什么是非托管代码? 什么是本地代码? 托 ...

  6. advertisingIdentifier

    iOS 7后Mac 地址就不能用了. 不过可以用advertisingIdentifier来取,再多个project 里测试是唯一的,但如果遇到系统升级或是重刷这个就不一定能唯一了.. 这里还要加一个 ...

  7. 微信小程序 - 自适应swiper高度(非组件)

    微信小程序swiper默认高度375rpx,一旦超过这高度,就滑动不到内容了,我们利用css3可以很简单做到这件事情 原理: 利用css3 横轴滚动属性overflow:scroll,设置死swipe ...

  8. hive中简单介绍分区表(partition table)——动态分区(dynamic partition)、静态分区(static partition)

    一.基本概念 hive中分区表分为:范围分区.列表分区.hash分区.混合分区等. 分区列:分区列不是表中的一个实际的字段,而是一个或者多个伪列.翻译一下是:“在表的数据文件中实际上并不保存分区列的信 ...

  9. Windows7安装UBUNTU虚拟机

    1.下载虚拟机:http://www.orsoon.com/Soft/12192.html 2.下载UBUNTU10.04:http://releases.ubuntu.com/lucid/ 3.安装 ...

  10. Eclipse Java注释模板设置详解以及版权声明

    网上的Eclipse注释模板,在这里稍稍整理一些比较常用的. 编辑注释模板的方法:Window->Preference->Java->Code Style->Code Temp ...