1023 Train Problem II(卡特兰数)
2
3
10
2
5
16796
The result will be very large, so you may not process it by 32-bit integers.
卡特兰数相关了解:
http://blog.csdn.net/wuzhekai1985/article/details/6764858
http://www.cnblogs.com/kuangbin/archive/2012/03/21/2410519.html
http://baike.baidu.com/link?url=SIrdv9w3YrmZdmGR5dIIszcQfzjndTjD9fHo1qzCYatFgsZIiwSbb2zOY70ouVcYZYES_1sbIXYuD1hbLaN78K
最初所写的代码(没考虑范围):
#include <stdio.h>
#include <algorithm>
int Catalan(int n){
if(n<=)
return ;
int *h = new int [n+];
h[] = h[] = ;
for(int i=;i<=n;i++){
h[i]=;
for(int j=;j<i;j++){
h[i]+=(h[j]*h[i--j]);
}
}
int result=h[n];
delete []h;
return result;
}
int main()
{
int n;
while(~scanf("%d",&n)){
printf("%d\n",Catalan(n));
}
return ;
}
bin神的模板:
#include <stdio.h> //*******************************
//打表卡特兰数
//第 n个 卡特兰数存在a[n]中,a[n][0]表示长度;
//注意数是倒着存的,个位是 a[n][1] 输出时注意倒过来。
//*********************************
int a[][];
void ktl()
{
int i,j,yu,len;
a[][]=;
a[][]=;
a[][]=;
a[][]=;
len=;
for(i=;i<;i++)
{
yu=;
for(j=;j<=len;j++)
{
int t=(a[i-][j])*(*i-)+yu;
yu=t/;
a[i][j]=t%;
}
while(yu)
{
a[i][++len]=yu%;
yu/=;
}
for(j=len;j>=;j--)
{
int t=a[i][j]+yu*;
a[i][j]=t/(i+);
yu = t%(i+);
}
while(!a[i][len])
{
len--;
}
a[i][]=len;
} }
int main()
{
ktl();
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=a[n][];i>;i--)
{
printf("%d",a[n][i]);
}
puts("");
}
return ;
}
1023 Train Problem II(卡特兰数)的更多相关文章
- HDU 1023 Train Problem II (卡特兰数,经典)
题意: 给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路: 卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. #inclu ...
- HDOJ 1023 Train Problem II 卡特兰数
火车进站出站的问题满足卡特兰数...卡特兰数的相关知识如下: 卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- C - Train Problem II——卡特兰数
题目链接_HDU-1023 题目 As we all know the Train Problem I, the boss of the Ignatius Train Station want to ...
- HDU-1023 Train Problem II 卡特兰数(结合高精度乘除)
题目链接:https://cn.vjudge.net/problem/HDU-1023 题意 卡特兰数的应用之一 求一个长度为n的序列通过栈后的结果序列有几种 思路 一开始不知道什么是卡特兰数,猜测是 ...
- HDU 1023 Train Problem II (大数卡特兰数)
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1023 Train Problem II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...
- HDU 1023 Train Problem II( 大数卡特兰 )
链接:传送门 题意:裸卡特兰数,但是必须用大数做 balabala:上交高精度模板题,增加一下熟悉度 /************************************************ ...
- HDU 1023 Train Problem II 大数打表Catalan数
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...
随机推荐
- 删CentOS / RHEL库和配置文件(Repositories and configuraiton files)
1 删除库简介 随着root权限执行以下的命令: # cd /etc/yum.repos.d/ 列出全部库(repo) #ls CentOS-Base.repo epel.repo mirrors-r ...
- poj1276--Cash Machine(多背包被判刑了)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 27804 Accepted: 9915 Des ...
- 【转】tomcat 访问软连接文件夹下的网页出现404错误,description The requested resource (/xxx.html) is not available.
在 tomcat/webapps/ROOT/ 下建立一个软连接文件ln -s /home/ubuntu/report report 再到report软连接目录里建立个 report.html通过浏 ...
- js的StringBuffer实施和使用类
<strong>JAVA有一个StringBuffer分类,js但不是在下面,以实现自己的简单js的StringBuffer分类.</strong> //创建一个StringB ...
- RH133读书笔记(10)-Lab 10 Exploring Virtualization
Lab 10 Exploring Virtualization Goal: To explore the Xen virtualization environment and the creation ...
- Python 获取Twitter用户与Friends和Followers的关系(eg, 交集,差集)
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-30 @author: guaguastd @name: f ...
- 为了圣像画系统V1.0Beta版(javascript)-GIS520社区
地图标绘系统V1.0測试版 (界面比較难看,之后再统一美化!) 演示地址:http://www.gis520.com/gis/plotdemo/index.html 查看可在菜单Map--> ...
- UVA10375 Choose and divide 质因数分解
质因数分解: Choose and divide Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- Ubuntu文件的复制、移动和删除命令
先说说cp复制命令 该命令的功能是将给出的文件或文件夹复制到还有一文件或文件夹中,同MSDOS下的copy命令一样,功能十分强大. 语法: cp [选项] 源文件或文件夹 目标文件或文件夹 说明:该命 ...
- LeetCode 48 Anagrams
Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be ...