题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1023

题目大意:

一列N节的火车以严格的顺序到一个站里。问出来的时候有多少种顺序。

解题思路:

典型的求Catalan数的题目,可是结果会非常大,所以须要用大数来解决。

Catalan公式为 h(n) = h(n-1) * (4*n-2) / (n + 1),h(0) = h(1) = 1。

AC代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 100;
const int BASE = 10000; void Multiply(int A[], int Max, int b) //大数乘法 A[]*b 10000进制
{
int Array = 0;
for(int i = Max - 1; i >= 0; --i)
{
Array += b * A[i];
A[i] = Array % BASE;
Array /= BASE;
}
} void Divide(int A[], int Max, int b) //大数除法 A[]/b 10000进制
{
int Div = 0;
for(int i = 0; i < Max; ++i)
{
Div = Div * BASE + A[i];
A[i] = Div / b;
Div %= b;
}
} int A[MAXN+10][MAXN+10]; int main()
{
memset(A,0,sizeof(A));
A[1][99] = 1;
for(int i = 2; i < 101; ++i)
{
for(int j = 0; j < 100; ++j)
A[i][j] = A[i-1][j];
Multiply(A[i], MAXN, 4*i-2);
Divide(A[i], MAXN, i+1);
}
int N;
while(~scanf("%d",&N) && N != -1)
{
int i;
for(i = 0; i < MAXN && A[N][i] == 0; ++i); //去掉数组前导0
printf("%d",A[N][i++]); //输出第一个非0数
for(; i < MAXN; ++i) //输出后边的数,每位保持4位长度
printf("%04d",A[N][i]);
printf("\n");
}
return 0;
}

HDU1023 Train Problem II【Catalan数】的更多相关文章

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

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

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

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

  3. ACM学习历程—HDU1023 Train Problem II(递推 && 大数)

    Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know  ...

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

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

  5. HDOJ 1023 Train Problem II 卡特兰数

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

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

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

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

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

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

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

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

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

随机推荐

  1. No enclosing instance of type E is accessible.

    No enclosing instance of type E  is accessible. 静态方法(main)中调用内部类,会出现这样的问题: 学习了:https://www.cnblogs.c ...

  2. 【LeetCode-面试算法经典-Java实现】【057-Insert Interval(插入区间)】

    [057-Insert Interval(插入区间)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a set of non-overlapping in ...

  3. Java中Socket上的Read操作堵塞问题

    从Socket上读取对端发过来的数据一般有两种方法: 1)依照字节流读取 BufferedInputStream in = new BufferedInputStream(socket.getInpu ...

  4. HDU 1730 Northcott Game

    简单的尼姆博弈.想到了非常easy! 就拿一行举例.怎么赢.? 就是死劲挨着对方移,当然假设本身就是挨着的,又轮到你移动了,那么对于这一行来讲.你就是输的!! 由此可见每一行的棋子起始距离就显得尤为重 ...

  5. MountService整理

    刚毕业时第一个接触的模块就是Vold.这个模块尽管小,但深入下去是有一定难度的. 花了点时间又一次整理了下这一块的逻辑,也当温习下这个模块. watermark/2/text/aHR0cDovL2Js ...

  6. vue2.0 vue-loader

    vue-cli npm install 脚手架: vue-loader 1.0 -> new Vue({ el: '#app', components:{App} }) 2.0-> new ...

  7. 26. Intellij IDEA 启动项目ClassNotFoundException

    转自:https://blog.csdn.net/zhw0596/article/details/81388147 使用Intellij IDEA  的过程中,新创建的项目启动时报 严重: Error ...

  8. 关于Hive在主节点上与不在主节点上搭建的区别之谈

    Hive不在主节点上搭建,我这里是在HadoopSlave1上.

  9. Retrofit请求数据对错误以及网络异常的处理

    http://blog.csdn.net/jdsjlzx/article/details/51566683

  10. 在Windows上如何安装和彻底卸载Adobe Flash Player教程

    很多小伙伴在安装水晶易表的时候,经常会遇到“Xcelsius2008需要使用Adobe Flash Player(9.151或者更高版本)”报错问题,如下图所示. 导致安装进程受阻,此时就需要安装高版 ...