题目链接_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. 学习了JsonSchema,我自定义了一个校验代码

    JsonSchema 使用fastjsonschema来校验数据 # 导入验证器 import json import fastjsonschema # 读取schema with open('../ ...

  2. Java中的两种异常类型是什么?他们有什么区别?

    一.Throwable是所有异常的根,java.lang.Throwable Error是错误,java.lang.Error Exception是异常,java.lang.Exception 二.E ...

  3. JVM系列四(内存分配策略).

    一.概要 前面的文章介绍了对象的创建过程,其中第三步 -- 分配内存,只是简单的介绍了分配的方式 -- 指针碰撞.空闲列表,其实内存在堆上分配还大有文章嘞. 对象的内存分配,往大方向上讲,就是在堆上分 ...

  4. 萌新入门Github请看这里,学不会远程教

    一些废话 本文的主旨是为初次接触Github的同学提供一个入门的教程,如果你已经是Github老鸟,可以忽略本文哦,另外本文只是抛砖引玉,其实最好的教程是官方文档!!! Github官网 Github ...

  5. C# -- DateTime与TimeSpan

    1. DateTime的使用 DateTime dt = DateTime.Now; StringBuilder sb = new StringBuilder(); sb.AppendLine(str ...

  6. CSS类的操作

    CSS类的操作 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...

  7. js获取当前时间的年月日时分秒以及时间的格式化

    1.获取当前时间 var myDate = new Date(); 2.获取时间中的年月日时分秒 myDate.getYear(); // 获取当前年份(2位) myDate.getFullYear( ...

  8. QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAllocEx failed.(遇到还没试过)

    今天在使用Redis的时候出现以下错误: QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAll ...

  9. 未来已来:云原生 Cloud Native

    作者:天知,原文链接 前言 自 2013 年容器(虚拟)技术(Docker)成熟后,后端的架构方式进入快速迭代的阶段,出现了很多新兴概念: 微服务 k8s Serverless IaaS:基础设施服务 ...

  10. JavaScript实例:运动的小球

    本篇博文通过制作一个小球运动动画的实例,来学习在HTML5的画布上实现动画制作的方法,同时理解面向对象程序设计的基本思想. 1.绘制小球 先在HTML页面中设置一个画布. <canvas id= ...