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

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

  1. #include <stdio.h>
  2. #include <algorithm>
  3. int Catalan(int n){
  4. if(n<=)
  5. return ;
  6. int *h = new int [n+];
  7. h[] = h[] = ;
  8. for(int i=;i<=n;i++){
  9. h[i]=;
  10. for(int j=;j<i;j++){
  11. h[i]+=(h[j]*h[i--j]);
  12. }
  13. }
  14. int result=h[n];
  15. delete []h;
  16. return result;
  17. }
  18. int main()
  19. {
  20. int n;
  21. while(~scanf("%d",&n)){
  22. printf("%d\n",Catalan(n));
  23. }
  24. return ;
  25. }

bin神的模板:

  1. #include <stdio.h>
  2.  
  3. //*******************************
  4. //打表卡特兰数
  5. //第 n个 卡特兰数存在a[n]中,a[n][0]表示长度;
  6. //注意数是倒着存的,个位是 a[n][1] 输出时注意倒过来。
  7. //*********************************
  8. int a[][];
  9. void ktl()
  10. {
  11. int i,j,yu,len;
  12. a[][]=;
  13. a[][]=;
  14. a[][]=;
  15. a[][]=;
  16. len=;
  17. for(i=;i<;i++)
  18. {
  19. yu=;
  20. for(j=;j<=len;j++)
  21. {
  22. int t=(a[i-][j])*(*i-)+yu;
  23. yu=t/;
  24. a[i][j]=t%;
  25. }
  26. while(yu)
  27. {
  28. a[i][++len]=yu%;
  29. yu/=;
  30. }
  31. for(j=len;j>=;j--)
  32. {
  33. int t=a[i][j]+yu*;
  34. a[i][j]=t/(i+);
  35. yu = t%(i+);
  36. }
  37. while(!a[i][len])
  38. {
  39. len--;
  40. }
  41. a[i][]=len;
  42. }
  43.  
  44. }
  45. int main()
  46. {
  47. ktl();
  48. int n;
  49. while(scanf("%d",&n)!=EOF)
  50. {
  51. for(int i=a[n][];i>;i--)
  52. {
  53. printf("%d",a[n][i]);
  54. }
  55. puts("");
  56. }
  57. return ;
  58. }

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. 最近做RTSP流媒体的实时广播节目

    //h264视频流打包代码 // NALDecoder.cpp : Defines the entry point for the console application. #include < ...

  2. Windows在结构Eclipse+Android4.0开发环境

    官方搭建步骤: http://developer.android.com/index.html 搭建好开发环境之前须要下载以下几个文件包: 一.安装Java执行环境JRE(没这个Eclipse执行不起 ...

  3. 十大经典数据挖掘算法(9) 朴素贝叶斯分类器 Naive Bayes

    贝叶斯分类器 贝叶斯分类分类原则是一个对象的通过先验概率.贝叶斯后验概率公式后计算,也就是说,该对象属于一类的概率.选择具有最大后验概率的类作为对象的类属.现在更多的研究贝叶斯分类器,有四个,每间:N ...

  4. zoj 2874 &amp; poj 3308 Paratroopers (最小割)

    意甲冠军: 一m*n该网络的规模格.详细地点称为伞兵着陆(行和列). 现在,在一排(或列) 安装激光枪,激光枪可以杀死线(或塔)所有伞兵.在第一i安装一排 费用是Ri.在第i列安装的费用是Ci. 要安 ...

  5. mysql 插入Emoji表情报错

    今天做的了个获取微信粉丝的功能,发现将昵称插入数据库报错.长度肯定是够的 Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F 找了点资料发现UTF-8编 ...

  6. [BEROR]CodeSign error: code signing is required for product type &#39;Application&#39; in SDK &#39;iOS 8.1&#39;

    解决方法: 选择project->Build Settings -> Code Signing -> Code Signing Identity -> Debug -> ...

  7. Matrix+POJ+二维树状数组初步

                                                                                                         ...

  8. memset功能的具体说明

    1.void *memset(void *s,int c,size_t n)总的效果:内存空间开辟了 s 第一 n 字节的值设置为一个值 c. 2.样本#include void main(){cha ...

  9. BZOJ 2038: [2009国家集训队]小Z的袜子(hose) 分块

    分块大法好 2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MB Submit: 2938  Solved: 13 ...

  10. 安装framework 3.5出现0x800F0922的解决方法

    关闭Windows 防火墙,启动Windows model install服务 重启! 再安装 就ok了