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. Python-注册登陆-20

    username = input('请输入你要注册的用户名:') password = input('请输入你要注册的密码:') with open('list_of_info',mode='w',e ...

  2. Stanford Word Segmenter的特定领域训练

    有没有人自己训练过Stanford Word Segmenter分词器,因为我想做特定领域的分词,但在使用Stanford Word Segmenter分词的时候发现对于我想做的领域的一些词分词效果并 ...

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

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

  4. SuperMaze(Hello World 团队)Alpha版使用说明

    一.产品介绍 超级迷宫是一款android的手机游戏,目前我们已经在PC 端成功实现大体功能,虽然虽然迷宫游戏不少但我们的游戏渐渐的会假如自己的特色功能,尽量吸引用户,通过游戏开发智力,通过游戏打发无 ...

  5. 5.1 四则运算单元测试j

    由于上个星期请假没上课,这个星期回来才知道作业,时间比较赶,个人能力又不足,作业质量不是很好 Calculator.java import java.util.Scanner; public clas ...

  6. JavaScript 编程易错点整理

    Case 1: 通过getElementById("id")获得是一个DOM元素节点对象: 通过getElementsByTagName("tagName")获 ...

  7. Activiti解析.bpmn文件获得User Task节点的CandidateUsers特性的值

    参考文档: http://www.cnblogs.com/mingforyou/p/5351332.html http://blog.csdn.net/jackyrongvip/article/det ...

  8. IP config with netsh under windows

    ================================================= CHINAUNICOME.bat route delete 0.0.0.0 mask 0.0.0.0 ...

  9. 【转帖】ARM的两种不同的CPU docker 应该也是支持arm的

    armel和armhf区别选择 知识经验  3年前 (2014-11-07)  20603浏览  1评论 目录 fpu单元 armel与armhf 安装armel和armhf arm-linux-gn ...

  10. MySQL下载安装详情教程

    1.下载MySQL数据库可以访问官方网站:https://www.mysql.com/ 2.点击DOWNLOADS模块下的Community模块下的MySQL Community Server进行下载 ...