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);
这里用的大数;
代码:
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<stack>
  7. using namespace std;
  8. const int INF=0x3f3f3f3f;
  9. #define mem(x,y) memset(x,y,sizeof(x))
  10. #define SI(x) scanf("%d",&x)
  11. #define PI(x) printf("%d",x)
  12. int N;
  13. //h( n ) = ( ( 4*n-2 )/( n+1 )*h( n-1 ) );
  14. int ans[][];
  15. void db(){
  16. ans[][]=;
  17. ans[][]=;
  18. ans[][]=;
  19. ans[][]=;
  20. int len=,yu=;
  21. for(int i=;i<=;i++){
  22. for(int j=;j<=len;j++){
  23. int t=ans[i-][j]*(*i-)+yu;
  24. yu=t/;
  25. ans[i][j]=t%;
  26. }
  27. while(yu){
  28. ans[i][++len]=yu%;
  29. yu/=;
  30. }
  31. for(int j=len;j>=;j--){
  32. int t=ans[i][j]+yu*;
  33. ans[i][j]=t/(i+);
  34. yu=t%(i+);
  35. }
  36. while(!ans[i][len])len--;
  37. ans[i][]=len;
  38. }
  39. }
  40. int main(){
  41. mem(ans,);
  42. db();
  43. while(~SI(N)){
  44. for(int i=ans[N][];i>=;i--)printf("%d",ans[N][i]);
  45. puts("");
  46. }
  47. return ;
  48. }

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. Unix/Linux环境C编程入门教程(23) 字符数字那些事儿

    1.atoi 包含头文件: #include <stdlib.h> 函数原型: int atoi( const char *str ); 功能:将字符串str转换成一个整数并返回结果.参数 ...

  2. 创建FBI树

    需求:数串由2^n个'0' '1'数串组成,对于一个数串,有01混合出现,则视为F,全0数串为B,全1数串为I. 将给定数串进行切割,如10010011可以用二叉树表示为 F(10010011) / ...

  3. Easyui treegrid复选框设置

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  4. #include <boost/scoped_ptr.hpp>

    多个元素使用#include <boost/scoped_array.hpp> 单个元素使用#include <boost/scoped_ptr.hpp> 作用域指针 它独占一 ...

  5. js实现车轮的来回滚动

    最近喜欢用js做车轮的来回滚动,简单的js动画分享给大家.有什么建议记得说出来大家一起讨论哦!效果图如下: 源代码: <style> #pic1{ width:20px; height:2 ...

  6. javascript第十五课:DOM

    dom就是文档,就是整个网页的简称,dom里面的标签就是对象 使用javascript进行DHMTL网页开发(Dynamic Html 动态网页) dom就是把html页面模拟成一个对象,顶级对象wi ...

  7. Hibernate缓存、组件、继承映射

    Hibernate缓存.组件.继承映射 三种状态: 临时状态:不受session管理,没有提交到数据库:没有执行sql之前,new对象的时候: 持久化状态:受session管理,提交到数据库:正在执行 ...

  8. pl/sql查询中文乱码

    1.设置系统环境变量 变量名:NLS_LANG 变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK 2.修改注册表 regedit->hkey_local_machine ...

  9. ARM上的linux如何实现无线网卡的冷插拔和热插拔

    ARM上的linux如何实现无线网卡的冷插拔和热插拔 fulinux 凌云实验室 1. 冷插拔 如果在系统上电之前就将RT2070/RT3070芯片的无线网卡(以下简称wlan)插上,即冷插拔.我们通 ...

  10. win7充分利用cpu来提供计算机性能

    在任务栏左下角点击开始菜单,在运行框内输入msconfig,在弹出的窗口点击“高级选项”,接着会弹出一个新窗口,我们勾选“处理器数”,在下拉菜单中按照自己的电脑配置进行选择,现在双核比较常见,当然也有 ...