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

卡特兰数相关了解:

http://blog.csdn.net/wuzhekai1985/article/details/6764858

http://www.cnblogs.com/kuangbin/archive/2012/03/21/2410519.html

http://baike.baidu.com/link?url=SIrdv9w3YrmZdmGR5dIIszcQfzjndTjD9fHo1qzCYatFgsZIiwSbb2zOY70ouVcYZYES_1sbIXYuD1hbLaN78K

最初所写的代码(没考虑范围):

 #include <stdio.h>
#include <algorithm>
int Catalan(int n){
if(n<=)
return ;
int *h = new int [n+];
h[] = h[] = ;
for(int i=;i<=n;i++){
h[i]=;
for(int j=;j<i;j++){
h[i]+=(h[j]*h[i--j]);
}
}
int result=h[n];
delete []h;
return result;
}
int main()
{
int n;
while(~scanf("%d",&n)){
printf("%d\n",Catalan(n));
}
return ;
}

bin神的模板:

 #include <stdio.h>

 //*******************************
//打表卡特兰数
//第 n个 卡特兰数存在a[n]中,a[n][0]表示长度;
//注意数是倒着存的,个位是 a[n][1] 输出时注意倒过来。
//*********************************
int a[][];
void ktl()
{
int i,j,yu,len;
a[][]=;
a[][]=;
a[][]=;
a[][]=;
len=;
for(i=;i<;i++)
{
yu=;
for(j=;j<=len;j++)
{
int t=(a[i-][j])*(*i-)+yu;
yu=t/;
a[i][j]=t%;
}
while(yu)
{
a[i][++len]=yu%;
yu/=;
}
for(j=len;j>=;j--)
{
int t=a[i][j]+yu*;
a[i][j]=t/(i+);
yu = t%(i+);
}
while(!a[i][len])
{
len--;
}
a[i][]=len;
} }
int main()
{
ktl();
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=a[n][];i>;i--)
{
printf("%d",a[n][i]);
}
puts("");
}
return ;
}

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

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

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

  2. HDOJ 1023 Train Problem II 卡特兰数

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

  3. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  4. C - Train Problem II——卡特兰数

    题目链接_HDU-1023 题目 As we all know the Train Problem I, the boss of the Ignatius Train Station want to ...

  5. HDU-1023 Train Problem II 卡特兰数(结合高精度乘除)

    题目链接:https://cn.vjudge.net/problem/HDU-1023 题意 卡特兰数的应用之一 求一个长度为n的序列通过栈后的结果序列有几种 思路 一开始不知道什么是卡特兰数,猜测是 ...

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

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

  7. hdu 1023 Train Problem II

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

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

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

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

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

随机推荐

  1. sql基础之DDL(Data Definition Languages)

    好久没写SQL语句了,复习一下. DDL数据定义语言,DDL定义了不同的数据段.数据库.表.列.索引等数据库对象的定义.经常使用的DDL语句包含create.drop.alter等等. 登录数据:my ...

  2. c# winform 中的 工具栏自动隐藏 splitter用法 带源码

    c# winform 中的 工具栏自动隐藏 splitter用法 带源码 代码下载地址 http://download.csdn.net/detail/simadi/7649313

  3. docker 真实---安装基本映像 (一)

    浸泡了几天的官方网站,正确docker有了更好的理解.准备着手建立一个公司的开发和测试环境,包含java.python. 环境介绍 首先说明一下我的环境 2物理server(以后简称为主机) 主机A配 ...

  4. SQLSERVER手动增长日志文件和数据文件

    原文:SQLSERVER手动增长日志文件和数据文件 SQLSERVER手动增长日志文件和数据文件 手动增长日志文件,实际上就是修改日志文件的大小  size 的单位是MB 下面设置日志文件大小是204 ...

  5. hdu4185 Oil Skimming(偶匹配)

    <span style="font-family: Arial; font-size: 14.3999996185303px; line-height: 26px;"> ...

  6. VS怎样创建和使用lib文件

    假设你当前正在使用vs写了一个project,那么你想如今就生成一个Lib文件,那么能够直接在"项目属性"上进行改动i 项目属性->配置属性->常规->配置类型中 ...

  7. Netty In Action中文版 - 第一章:Netty介绍

    本章介绍 Netty介绍 为什么要使用non-blocking IO(NIO) 堵塞IO(blocking IO)和非堵塞IO(non-blocking IO)对照 Java NIO的问题和在Nett ...

  8. Linux查看命令终止进程

    Linux查看命令终止进程 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ps PID TTY TIME CMD 2576 pts/0 00:00:00 ba ...

  9. 照片教你eclipse通过使用gradle 打包Android

    gradle其他优点不说,在android当应用程序公布.假设你要算一些渠道,gradle 在节目包装散装优势:下面给大家介绍的图形 按eclipse当出口 选择Android:例如下面的附图 一步一 ...

  10. InputMonitor注意事项

    文章只记录自己的点点理解.为了你自己的参考. 1.mInputFocus WMS.addWindow()-->WMS.finishUpdateFocusedWindowAfterAssignLa ...