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. Linux系统中最好用的截图软件介绍

    当我的主力操作系统从 Windows 转换到 Ubuntu 的时候,首要考虑的就是屏幕截图工具的可用性.尽管使用默认的键盘快捷键也可以获取屏幕截图,但如果使用屏幕截图工具,可以更方便地对屏幕截图进行编 ...

  2. Java-JUC(七):同步锁的几种方式

    为什么要使用同步锁? 因为当使用多线程同时访问一个变量或对象时,如果这些线程中即有读又有写操作时,会造成导致变量或对象的状态出现混乱.例如:一个银行账户被A/B两个线程同时操作,A线程.B线程同时开始 ...

  3. 【矩阵乘】【DP】【codevs 1305】Freda的道路

    1305 Freda的道路 时间限制: 1 s 空间限制: 128000 KB 题目等级: 大师 Master 题目描写叙述 Description Freda要到Rainbow的城堡去玩了. 我们能 ...

  4. 一个ActiveX control的创建过程

    创建 根据这篇文章的介绍:http://www.cnblogs.com/time-is-life/p/6354152.html 来创建,里面包含了创建的基本过程以及属性事件方法的使用. 使用: 参考文 ...

  5. idea缓存目录mac cache

    IDEA如果出现卡顿,Index疯狂扫描,建议清空一下如下目录 ~/Library/Caches/IntelliJIdea2017.3 Resource nexus-maven-repository- ...

  6. [Angular] Communicate with Angular Elements using Inputs and Events

    In a real world scenario we obviously need to be able to communicate with an Angular Element embedde ...

  7. 解决jetty runner锁定js

    在web.xml中添加 <servlet> <!-- Override init parameter to avoid nasty --> <!-- file locki ...

  8. Android 之 PackageManager获取的应用程序信息与AndroidManifest文件中设置的信息不一致问题

    有时我们需要用 PackageManager 来获取应用程序的版本号和版本名称等信息,通过以下代码来获取: PackageManager manager = getPackageManager(); ...

  9. PD 之 连接数据库并导出数据及生成PDM文件

    使用PowerDesigner工具,连接数据库并导出数据及生成PDM文件. 1.建立连接 “以管理员身份运行”打开PowerDesigner,右键“Workspace”→“New”→“Physical ...

  10. postman发送get请求

    在地址栏里输入请求url(用到拼接方式):http://127.0.0.1:8081/getuser?userid=1 选择“GET”方式, 点击“send”得到json数据如图   分类: post ...