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. 【收藏】介绍RCU的好文章

    RCU原理: RCU(Read-Copy Update),顾名思义就是读-拷贝修改,它是基于其原理命名的.对于被RCU保护的共享数据结构,读者不需要获得任何锁就可以访问它,但写者在访问它时首先拷贝一个 ...

  2. unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题

    最近开发中在对场景进行光照贴图烘焙时发现一个坑爹问题,在使用自定义shader的时候,shader命名中必须包含Transparent路径,否则烘焙的时候不对alpha通道进行计算,烘焙出来都是狗皮膏 ...

  3. libsvm使用说明

    http://www.hankcs.com/ml/libsvm-usage.html libsvm使用说明 码农场 > 机器学习 2016-02-18 阅读(345) 评论(0)  目录   l ...

  4. MySQL老是提示视图没有主键

    写了一个视图,每次打开都提示没有主键.我又不想更新视图,根本不关心这个,但每次都提示,很烦. 网上找到解决办法,就是关闭提示: Windows 和 Linux:选择工具 > 选项,并在外观 &g ...

  5. OpenGL ES3 非常好的系列文章

    OpenGL ES3 非常好的系列文章: OpenGL-ES 3.0学习指南(五)--EGL基础 NDK开发OpenGL ES 3.0(二)--初见GLES,第一个三角形 NDK开发OpenGL ES ...

  6. 如何检查显卡类型,DirectX和OpenGL的版本

    How To: Check the graphics card type and OpenGL version From: http://support.esri.com/technical-arti ...

  7. 公共Maven库

    <repository><id>codelds</id><url>https://code.lds.org/nexus/content/groups/m ...

  8. Ubuntu MYSQL环境搭建

    前期准备: 检查系统资源 内存大小 # grep MemTotal/proc/meminfo 检查系统版本 统一为: Ubuntu 12.04.1 LTS(GNU/Linux 3.2.0-29-gen ...

  9. Linux Centos7中MySql安装

    (1)     安装Mysql5.7: 执行命令:rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-co ...

  10. Mysql官方文档中争对安全添加列的处理方法。Mysql Add a Column to a table if not exists

    Add a Column to a table if not exists MySQL allows you to create a table if it does not exist, but d ...