题意:

给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能。    (题于文末)

知识点:

ps:百度百科的卡特兰数讲的不错,注意看其参考的博客。

卡特兰数(Catalan):前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670…

令h(0)=1,h(1)=1,catalan数满足递推式:

     h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2)

另类递推式:

递推关系的解为:

递推关系的另类解为:

对于在2n位的2进制中,有n个0,其余为1,且1的累计数>=0的累计数,二进制数有

对于在n位的2进制中,有m个0,其余为1的catalan数为:

理解:catalan数的理解

应用:

1.出栈次序: 一个栈(无穷大)的进栈序列为1,2,3,…,n,有多少个不同的出栈序列?          h(n)种。

2.给定节点组成二叉树:给定n个节点,能构成多少种不同的二叉树?    h(n)种。

3.括号化:矩阵连乘,依据乘法结合律,不改变其顺序,只用括号表示成对的乘积,有几种括号化的方案?  h(n-1)种。

4.凸多边形三角划分:在一个凸n边形中,通过若干条互不相交的对角线,有多少种方法把这个多边形划分成若干个三角形?         h(n-2)种。

/**/

题解:

此题为应用1,运用公式  

catalan数计算一般都涉及大数运算,java写起来方便。

import java.util.Scanner;
import java.math.BigInteger;
import java.io.*; public class Main{
public static void main(String[] args){
int n;
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
n=sc.nextInt();
BigInteger ans=BigInteger.valueOf(1);
for(int i=1;i<=n;i++){
ans=ans.multiply(BigInteger.valueOf(4*i-2));
ans=ans.divide(BigInteger.valueOf(i+1));
}
System.out.println(ans);
}
}
}

Train Problem II

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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. 

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

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

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

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

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

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

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

  4. HDOJ 1023 Train Problem II 卡特兰数

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

  5. Train Problem II(卡特兰数+大数乘除)

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

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

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

  7. Train Problem II(卡特兰数 组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...

  8. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

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

  9. hdu 1023 Train Problem II

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

随机推荐

  1. .NET MVC4 Razor视图预编译(一)

    在平时使用.NET MVC中不乏有类似的需求:某些razor视图,特别是系统后台的视图,不想让用户自行更改,需要通过某种方法把视图模板编译到项目的dll中去. 但是VS并不提供razor的预编译,如果 ...

  2. JSP实现word文档的上传,在线预览,下载

    前两天帮同学实现在线预览word文档中的内容,而且需要提供可以下载的链接!在网上找了好久,都没有什么可行的方法,只得用最笨的方法来实现了.希望得到各位大神的指教.下面我就具体谈谈自己的实现过程,总结一 ...

  3. 自己封装了一个EF的上下文类.,分享一下,顺便求大神指点

    using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...

  4. CSS知识总结(六)

    CSS常用样式 4.段落样式 1)行高 控制段落内每行高度 line-height : normal | length 例子 源代码: /* CSS代码 */ .normal{ line-height ...

  5. Ionic2系列——Ionic 2 Guide 官方文档中文版

    最近一直没更新博客,业余时间都在翻译Ionic2的文档.之前本来是想写一个入门,后来觉得干脆把官方文档翻译一下算了,因为官方文档就是最好的入门教程.后来越翻译越觉得这个事情确实比较费精力,不知道什么时 ...

  6. Unity 3D json嵌套使用以及多种类型匹配

    我们控制端要发送很多命令给终端设备,其中有速度,方向,开关门,开关灯....方法千万种,我只取一瓢.我还小,不知道其他人是怎么写的.我喜欢把有规律的东西放在一起写!为了我的强迫症! using Uni ...

  7. C#——this关键字(1)

    //我的C#是跟着猛哥(刘铁猛)(算是我的正式老师)<C#语言入门详解>学习的,微信上猛哥也给我讲解了一些不懂得地方,对于我来说简直是一笔巨额财富,难得良师! 在学习C#的时候,老师讲的示 ...

  8. ToolsCodeTemplate使用

    最近学习使用CodeSmith代码生成器 CodeSmith 是一种语法类似于asp.net的基于模板的代码生成器,程序可以自定义模板,从而减少重复编码的劳动量,提高效率. 作用:CodeSmith ...

  9. shell 带签名请求,yii 处理带签名的请求

    处理请求 class TestController extends Controller { public function init() { if(!YII_ENV_DEV){ throw new ...

  10. Node.js的Formidable模块的使用

    今天总结了下Node.js的Formidable模块的使用,下面做一些简要的说明. 1)     创建Formidable.IncomingForm对象 var form = new formidab ...