题意:

给你一个数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. JavaScript权威设计--事件冒泡,捕获,事件句柄,事件源,事件对象(简要学习笔记十八)

    1.事件冒泡与事件捕获 2.事件与事件句柄   3.事件委托:利用事件的冒泡技术.子元素的事件最终会冒泡到父元素直到跟节点.事件监听会分析从子元素冒泡上来的事件. 事件委托的好处:     1.每个函 ...

  2. jquery实现Tab选项卡菜单

    效果图: 默认选中  科技                                                                                 当鼠标悬停在 ...

  3. Java学习之LinkedHashMap学习总结

    前言: 在学习LRU算法的时候,看到LruCache源码实现是基于LinkedHashMap,今天学习一下LinkedHashMap的好处以及如何实现lru缓存机制的. 需求背景: LRU这个算法就是 ...

  4. .NET Core的文件系统[3]:由PhysicalFileProvider构建的物理文件系统

    ASP.NET Core应用中使用得最多的还是具体的物理文件,比如配置文件.View文件以及网页上的静态文件,物理文件系统的抽象通过PhysicalFileProvider这个FileProvider ...

  5. request中getParameter和getAttribute的区别

    整理一下getParameter和getAttribute的区别和各自的使用范围. (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方 ...

  6. php数据库访问及增删改

    利用PHP访问由MySQL构建的数据库 连接到数据库 //1.造连接对象 $db = new MySQLi("localhost","root","1 ...

  7. 使用OAuth、Identity创建WebApi认证接口供客户端调用

    前言 现在的web app基本上都是前后端分离,之前接触的大部分应用场景最终产品都是部署在同一个站点下,那么随着WebApi(Restful api)的发展前后端实现的完全分离,前端不在后端框架的页面 ...

  8. [收藏]IntelliJ Idea快捷键

    Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码(如g ...

  9. [解决方案]CREATE DATABASE statement not allowed within multi-statement transaction.

    CREATE DATABASE statement not allowed within multi-statement transaction. 刚开始报这个错误的时候,我上度娘搜了一下. 别人是在 ...

  10. facebook充值实时更新接口文档翻译 希望对做facebook充值的小伙伴有帮助

    Realtime Updates for Payments are an essential method by which you are informed of changes to orders ...