火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下:

卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列。由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。

前几项为 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, ...

令h(1)=1,h(2)=1,catalan数满足递归式:

例如:h(3)=h(1)*h(2)+h(2)*h(1)=1*1+1*1=2

 h(4)=h(1)*h(3)+h(2)*h(2)+h(3)*h(1)=1*2+1*1+2*1=5

h(0)=1;h(1)=1;h(2)=2;h(3)=5;  ····有另类的递归式

另类递归式:

  h(n)=h(n-1)*(4*n-2)/(n+1);

  该递推关系的解为:

h(n)=C(2n,n)/(n+1) (n=1,2,3,...)

可以看出卡特兰数是一个大数据的问题,处理大数据问题一般是将数据的各位存放在一个数组中....

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

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

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

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

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

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

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

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

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

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

  5. HDOJ 1023 Train Problem II

    考虑第1个火车出站的时刻,从1到n都有可能,如果它是第i个出栈,那么前面有规模为i-1的子问题,后面有规模为n-i的子问题.累加.

  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. 1023 Train Problem II(卡特兰数)

    Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...

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

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

随机推荐

  1. 08-THREE.JS 点面创建物体,克隆物体,多材质物体

    <!DOCTYPE html> <html> <head> <title></title> < <script src=&quo ...

  2. vs2010 oraclelient 引用问题

    不能正常引用 oracleclent :错误信息如下 ================================================================= 排除1. 当前 ...

  3. LeetCode OJ:Combination Sum III(组合之和III)

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  4. listening 1

    It was regrettable that such great issues had to be the thrust and parry of a general election. But ...

  5. 整理下PC和移动获取点击、移动坐标的代码和坑

    一.PC PC是通过鼠标点击和移动,相对比较简单,比如onmousedown.onmouseup.onmousemove.onmouseout鼠标按键按下.按键起来.鼠标在元素上移动.鼠标从元素上离开 ...

  6. Eclipse之Web工程探究以及格式化

    1. 关于部署 只要配置了Web Deployment Assembly,可以不需要手工拷贝引用jar到/WEB-INF/lib里面了,之前失败是因为引用工程的output路径有问题导致的,修改完成后 ...

  7. Qt中如何用QImage::Format_Indexed8表示灰度图

    QImage *qi = new QImage(data_ptr, width, height, QImage::Format_Indexed8); QVector<QRgb> grayT ...

  8. java流类练习前篇

    总结: package com.aini; import java.io.*; public class gf { public static String main(String[] args) t ...

  9. 2018年长沙理工大学第十三届程序设计竞赛 Dzzq的离散数学教室1

    Dzzq的离散数学教室1 链接:https://www.nowcoder.com/acm/contest/96/D来源:牛客网 zzq的离散数学教室1 时间限制:C/C++ 1秒,其他语言2秒 空间限 ...

  10. 杂项:C# 方法、属性杂项-01

    ylbtech-杂项:C# 方法.属性杂项-01 1. 属性杂项返回顶部 1. public int ReadCnt { get; set; } 2.设置默认值 public int ReadCnt ...