题目链接_HDU-1023

题目

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

思路:

仔细一看,就是让你求卡特兰数,只不过这个数的范围大了点,会爆long long ,所以要用数组来进行存储。这道题的核心应该就是让求大数对一个较小的数的乘法和除法。

而这个乘法和除法(因为是对一个较小的数的操作)所以就是简单的模拟我们平常手算对数的乘法和除法。

具体代码实现如下:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[2005];
void mu(int k)
{
int c=0;
for(int i=1;i<=2000;i++)
{
int u=a[i]*k+c;
a[i]=u%10;
c=u/10;
} }
void chu(int k)
{
int c=0;
for(int i=2000;i>=1;i--)
{
int u=a[i]+c;
a[i]=u/k;
c=u%k*10;
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(a,0,sizeof(a));
a[1]=1;
for(int i=n+1;i<=2*n;i++)
{
mu(i);
}
for(int i=1;i<=n+1;i++)
{
chu(i);
}
int flog=0;
for(int i=2000;i>=1;i--)
{
if(a[i]!=0)
{
flog=1;
}
if(flog==1)
{
printf("%d",a[i]);
}
}
printf("\n");
}
return 0;
}

C - 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. 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. JS基础-事件队列

    为什么JavaScript是单线程? JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事.那么,为什么JavaScript不能有多个线程呢?这样能提高效率啊. JavaSc ...

  2. newifi 1.6.13上运行mentohust方案

    newifi最新版的固件,已经无法简单的root和开启ssh了,以下是本人的解决方案. 一·刷上pandorabox系统 1.系统可以到联想NBD社区下载:http://www.newbandeng. ...

  3. fineuploader php服务端

    新版本的fineuploader项目中已经没有现成的php server端,需要额外使用composer进行安装,折腾好久才下下来,在此分享出来给大家. 下载地址: http://files.cnbl ...

  4. Asp.Net MVC中Aplayer.js音乐播放器的使用

    1.前言: Aplater.js是一款可爱.漂亮的Js音乐播放器,以前就了解过也弄过一些,现在就用mp3的格式来在.Net里面开发.管网 https://aplayer.js.org/ 2.入手: 在 ...

  5. django生命周期请求l流程图

    django思维导图链接:https://www.processon.com/view/link/5dddb0f8e4b074c442e5c68c

  6. flink time and watermark

    流处理中时间本质上就是一个普通的递增字段(long型,自1970年算起的微秒数),不一定真的表示时间. watermark只是应对乱序的办法之一,大多是启发式的,在延迟和完整性之间抉择.(如果没有延迟 ...

  7. keras实现mnist手写数字数据集的训练

    网络:两层卷积,两层全连接,一层softmax 代码: import numpy as np from keras.utils import to_categorical from keras imp ...

  8. laravel起步的一些小问题

    工作中主要使用的是.NET,PHP只是我业余喜欢的一门语言,而之前一直用的是yii2框架,觉得Yii2是最好的框架了,然而,laravel在业界的名声太大,被誉为:最优雅的框架,所以,我决定花点时间研 ...

  9. Python面向对象-类、实例的绑定属性、绑定方法和__slots__

    绑定属性 从之前的文章中,我们知道python是动态语言——实例可以绑定任意属性. 那如果实例绑定的属性和类的属性名一样的话,会是什么情况呢? >>> class Student(o ...

  10. Supermap/Cesium 开发心得----动态散点图(波纹点/涟漪点)

    在二维开发中,openlayers4 入门开发系列结合 echarts4 实现散点图,下图是GIS之家的效果图,那么在三维中,则可借助Entity来变相构造下图的效果. 思路: 构造实体ellipse ...