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. URL组成介绍

    1.2. HTTP request ----------------- First, let's consider this HTTP request : Line Contents number 1 ...

  2. windows2003 64位注册码 序列号 激活码

    Windows 2003 R2 64bit Enterprise VOL Edition 企业版 MR78C-GF2CY-KC864-DTG74-VMT73 VPT7T-77D38-KWVW2-2G3 ...

  3. python安装完毕后,提示找不到ssl模块的解决方示

    python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python2.7.5 Python 2.7.5 (default, Jun 3 2013, 11:08:43) ...

  4. JS正则表达式大全【转】

    正则表达式中的特殊字符 字符 含意 \ 做为转意,即通常在"\"后面的字符不按原来意义解释,如/b/匹配字符"b",当b前面加了反斜杆后/\b/,转意为匹配一个 ...

  5. WordPress中文汉字username不能注冊怎么办?

    WordPress注冊用户是不支持中文的.可是近期在项目中须要用到中文注冊. 后来想到了简单的处理办法: 打开 wp-includes/formatting.php.找到 function sanit ...

  6. 解决Win7&Win8 64位下Source Insight提示未完整安装的问题

    网上的破解版的注册表文件都是针对32位系统的,所以在64位系统里运行根本无法破解.下面分别贴出这俩系统里的破解文件. 使用方法: 分别复制对应系统的内容,新建文本文档,将内容粘贴进去,重命名为.reg ...

  7. 固定表格行列(expression)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  8. 【最小费用最大流模板】【Uva10806+Spring Team PK】Dijkstra, Dijkstra,

    题意:从1到n 再从n到1 不经过重复的边 ,(如果是点就是旅行商问题了),问最短路 建立一个超级源S S到1连一条费用为0,容量为2的边,求费用流即可 如果流<2 那么hehe 否则    输 ...

  9. Tomcat无法安装 Check your settings and permissions Ignore and continue anyway

    刚刚“sj”,把装在C盘的tomcat的文件夹给删除了,刚删完就想到干嘛不卸载啊,哎惯性思维啊,转而一想,tomcat这么简单安装,不怕不怕,后来一装,妈啊,装不了,百度之后原来是服务没有删除,好吧, ...

  10. SqlServer2008(R2) 数据库使用外网IP实例连接服务器

    1.打开sql2008,使用windows身份登录 2.登录后,右键选择"属性".左侧选择"安全性",选中右侧的"SQL Server 和 Windo ...