Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 10372    Accepted Submission(s): 5543

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)=h(n-1)*(4*n-2)/(n+1)。

用JAVA更简单:

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
BigInteger a[]=new BigInteger[101];
a[0]=BigInteger.ZERO;
a[1]=BigInteger.ONE;
for(int i=2;i<=100;i++)
a[i]=a[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
while(in.hasNextInt()) {
int n=in.nextInt();
System.out.println(a[n]);
}
}
}

接下来是C++:

#include <iostream>
#include <cstdio>
using namespace std;
int a[][];
int i,j,n;
void ctl() //打表。
{
a[][]=;
a[][]=;
a[][]=;
a[][]=;
int len=,t,yu=; //注意初始化。
for(i=;i<;i++) //先打表求出1到100的所有Catalan数。
{
for(j=;j<=len;j++) //大数乘法。
{
t=a[i-][j]*(*i-)+yu;
yu=t/;
a[i][j]=t%; //求每位数的确定的数。
}
while(yu) //进位。一直到yu为0为止。
{
a[i][++len]=yu%;
yu/=;
}
for(j=len;j>=;j--) //大数除法。联系手工除法步骤。
{
t=a[i][j]+yu*;
a[i][j]=t/(i+); //可以看做手工除法的商。
yu=t%(i+); //可以看做手工除法的余数。
}
while(!a[i][len]) //去掉前边的0。
{
len--;
}
a[i][]=len;
}
}
int main()
{
ctl();
int n;
while(~scanf("%d",&n))
{
for(int i=a[n][];i>;i--)
{
printf("%d",a[n][i]);
}
puts("");
}
return ;
}

(母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023的更多相关文章

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

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

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

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

  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. hdu1032 Train Problem II (卡特兰数)

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

  5. Train Problem II(卡特兰数 组合数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023 Train Problem II Time Limit: 2000/1000 MS (Java/ ...

  6. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

  7. HDU——1023 Train Problem II

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

  8. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

  9. 求解Catalan数,(大数相乘,大数相除,大数相加)

    Catalan数 卡塔兰数是组合数学中一个常在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰(1814–1894)命名.历史上,清代数学家明安图(1692年-1763年)在其<割圜 ...

随机推荐

  1. 结构体内嵌比较函数bool operator < (const node &x) const {}

    直接看别人的链接 [http://www.cnblogs.com/ZERO-/p/9347296.html]

  2. ResultSet集合查询字段名称(转载)

    转自:https://blog.csdn.net/song_litao/article/details/84751351 public List<String> getColumnName ...

  3. Linux 第八周实验 进程的切换和系统的一般执行过程

    姬梦馨 原创作品 <Linux内核分析>MOOC课程:http://mooc.study.163.com/course/USTC-1000029000 第八讲 进程的切换和系统的一般执行过 ...

  4. 5.2&5.3

    队友吕日荣 http://www.cnblogs.com/Russelling/ 最近队友有点忙,尽管如此,队友还是有很给力的付出,让我们在最后完成了任务. 一开始都不知道这次的任务是要做什么,毫无头 ...

  5. java中实现全局变量的功能

    一.通过接口实现 二.通过静态变量  static声明 package test.autorun; import java.util.LinkedList; import java.util.Queu ...

  6. 【转】进程同步之信号量机制(pv操作)及三个经典同步问题

    原文地址:http://blog.csdn.net/speedme/article/details/17597373 上篇博客中(进程同步之临界区域问题及Peterson算法),我们对临界区,临界资源 ...

  7. [系统软件]Ubuntu 18.04中的Shutter禁用了“编辑”选项解决

    本文引用自linux公社, 原文请点击 : https://www.linuxidc.com/Linux/2018-04/151911.htm   在Ubuntu 18.04中安装了我最喜欢的截图工具 ...

  8. Java WebDriver 使用经验

    0x00 背景 WebDriver作为Selenium项目的工具之一,可以高效的操作各类主流浏览器包括诸如:chrome.IE.Firefox.Safari,并同时支持windows和*nux系统.W ...

  9. windows 与linux 上面PG的简单验证

    0.0 目的 验证一下 windows 上面 和linux上面的数据文件是否可以 冷备份 恢复. 1 方法关闭 windows机器上面postgresql 的服务 我这边是PG10.4 可以使用命令 ...

  10. CMake--Set用法

    CMake中的set用于给一般变量,缓存变量,环境变量赋值. cmake官方文档set set(<variable> <value> [[CACHE <type> ...