Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7539    Accepted Submission(s): 4062

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.

 
题解:卡特兰数:h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) );也可以用java,h(n)= h(0)*h(n-1) + h(1)*h(n-2) + + h(n-1)h(0) (其中n>=2);
这里用的大数;
代码:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
int N;
//h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) );
int ans[][];
void db(){
ans[][]=;
ans[][]=;
ans[][]=;
ans[][]=;
int len=,yu=;
for(int i=;i<=;i++){
for(int j=;j<=len;j++){
int t=ans[i-][j]*(*i-)+yu;
yu=t/;
ans[i][j]=t%;
}
while(yu){
ans[i][++len]=yu%;
yu/=;
}
for(int j=len;j>=;j--){
int t=ans[i][j]+yu*;
ans[i][j]=t/(i+);
yu=t%(i+);
}
while(!ans[i][len])len--;
ans[i][]=len;
}
}
int main(){
mem(ans,);
db();
while(~SI(N)){
for(int i=ans[N][];i>=;i--)printf("%d",ans[N][i]);
puts("");
}
return ;
}

Train Problem II(卡特兰数+大数乘除)的更多相关文章

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

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

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

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

  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 (卡特兰数,经典)

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

  5. HDOJ 1023 Train Problem II 卡特兰数

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

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

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

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

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

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

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

  9. HDU_1023_Train Problem II_卡特兰数

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

随机推荐

  1. Java ClassLoader深入讲解(转)

    当JVM(Java虚拟机)启动时,会形成由三个类加载器组成的初始类加载器层次结构: bootstrap classloader                |       extension cla ...

  2. extjs让按钮可用或者不可用

    Ext.getCmp(‘按钮ID’).enable();//设置为可用Ext.getCmp(‘按钮ID’).disable();//设置为不可用

  3. VC连接SQL server2005

    VC连接SQL server2005 1.创建一个MFC对话框程序 界面如下 2.创建一个成员变量 这个成员变量用于连接数据库 3.响应按钮函数OnButton1() 在响应函数里主要有三个函数 函数 ...

  4. php float 转int

    round(x,prec) 参数 描述 x 可选.规定要舍入的数字. prec 可选.规定小数点后的位数. <?php echo(round(0.60)); echo(round(0.50)); ...

  5. Android解决异常apk on device '0292bea1': Unable to open sync connection!

    方式一:使用手机管家(如腾讯手机管家,只要拖动发射火箭就行了)清理一下正在运行的后台程序. 方式二:把USB数据线拔了重新链接. 方法三:找到USB调试,关掉USB调试,然后重新开启.在设置 --&g ...

  6. 学用 ASP.Net 之 System.Math 类

    本文来自:http://www.cnblogs.com/del/archive/2011/01/03/1924746.html   成员: /* 字段 */ Math.E;      //2.7182 ...

  7. linux下的时间及时区设置

    一.时间设置及同步 1修改系统时间 #date -s 06/18/14 #date -s 14:20:50 2命令查看.设置硬件时间 #hwclock  --show 或者clock  --show ...

  8. js写的复制功能,只支持IE

    如果用js写,只能支持IE,如果想全支持,需要用jQuery的插件:jquery.zclip.js 下面是用js写的: var copyHref = function(){               ...

  9. Spring事务传播机制详解

    1 事务的传播属性(Propagation) 1) REQUIRED ,这个是默认的属性 Support a current transaction, create a new one if none ...

  10. Oracle的关于建表,约束,查询等的练习

    从建立一个简单表,到实现一些复杂查询的例子, DROP TABLE grade;DROP TABLE item;DROP TABLE sporter;CREATE TABLE sporter( spo ...