这个就是卡特兰数的经典问题

直接用这个公式就好了,但是这个题涉及大数的处理h(n)=h(n-1)*(4*n-2)/(n+1)

其实见过好几次大数的处理了,有一次他存的恰好不多于30位,直接分成两部分long long 存了

这个只涉及到大数乘小数,大数除以小数,所以比较简单些

3551: Game of Connections 

Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
Total Submit: 5            Accepted:4

Description

This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, ... , 2n - 1, 2n consecutively in clockwise order on the ground to form a circle, and then, to draw some straight line segments to connect them into number pairs. Every number must be connected to exactly one another. And, no two segments are allowed to intersect.

It's still a simple game, isn't it? But after you've written down the 2n numbers, can you tell me in how many different ways can you connect the numbers into pairs? Life is harder, right?

Input

Each line of the input file will be a single positive number n, except the last line, which is a number -1. You may assume that 1 <= n <= 100.

Output

For each n, print in a single line the number of ways to connect the 2n numbers into pairs.

Sample Input

2
3
-1

Sample Output

2
5

Hint

The result may exceed 2^64.

#include <stdio.h>
int a[][];
int main()
{
a[][]=;
for(int i=; i<; i++)
{
int c=;
for(int j=; j<; j++)
{
a[i][j]=a[i-][j]*(*i-)+c;
c=a[i][j]/;
a[i][j]%=;
}
c=;
for(int j=; j>=; j--)
{
c=c*+a[i][j];
a[i][j]=c/(i+);
c%=(i+);
}
}
int n;
while(~scanf("%d",&n),n>)
{
int t=;
while(a[n][t]==)t--;
while(t>=)printf("%d",a[n][t--]);
putchar();
}
return ;
}

 

组合数学的卡特兰数 TOJ 3551: Game of Connections的更多相关文章

  1. CodeForces - 1204E Natasha, Sasha and the Prefix Sums (组合数学,卡特兰数扩展)

    题意:求n个1,m个-1组成的所有序列中,最大前缀之和. 首先引出这样一个问题:使用n个左括号和m个右括号,组成的合法的括号匹配(每个右括号都有对应的左括号和它匹配)的数目是多少? 1.当n=m时,显 ...

  2. uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

    option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...

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

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

  4. hdu5673 Robot 卡特兰数+组合数学+线性筛逆元

    Robot Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  5. CodeForces - 896D :Nephren Runs a Cinema(卡特兰数&组合数学---比较综合的一道题)

    Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. Howev ...

  6. [luogu1485 HNOI2009] 有趣的数列 (组合数学 卡特兰数)

    传送门 Solution 卡特兰数 排队问题的简单变化 答案为\(C_{2n}^n \pmod p\) 由于没有逆元,只好用分解质因数,易证可以整除 Code //By Menteur_Hxy #in ...

  7. 卡特兰数(Catalan)

    卡特兰数又称卡塔兰数,英文名Catalan number,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名,其前几项为 : 1, 2, ...

  8. 卡特兰数(Catalan Number) 算法、数论 组合~

    Catalan number,卡特兰数又称卡塔兰数,是组合数学中一个常出现在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名. 卡特兰数的前几个数 前20项为( ...

  9. 卡特兰数 Catalan数 ( ACM 数论 组合 )

    卡特兰数 Catalan数 ( ACM 数论 组合 ) Posted on 2010-08-07 21:51 MiYu 阅读(13170) 评论(1)  编辑 收藏 引用 所属分类: ACM ( 数论 ...

随机推荐

  1. 移动端REM布局模板(阿里高清方案)

    移动端REM布局模板(阿里高清方案),蛮好的,转自: http://www.jianshu.com/p/985d26b40199 . <!DOCTYPE html> <html la ...

  2. 《深入理解JavaScript闭包和原型》笔记

    By XFE-堪玉 以下知识来源于对王福朋所写<深入理解javascript原型和闭包>的理解和整理 一切都是对象[引用类型],对象都是通过函数创建的[Funcion类型] 对象是属性的集 ...

  3. (转)ASIC设计中各个阶段需要注意的问题——节选

    ASIC 的复杂性不断提高,同时工艺在不断地改进,如何在较短的时间内开发一个稳定的可重用的ASIC芯片的设计,并且一次性流片成功,这需要一个成熟的ASIC 的设计方法和开发流程.本文结合NCveril ...

  4. ASP.NET MVC执行流程图

  5. PCL点云处理可视化——法向显示错误“no override found for vtk actor”解决方法

    转:https://blog.csdn.net/bflong/article/details/79137692 参照:https://blog.csdn.net/imsaws/article/deta ...

  6. iOS上架问题解决

    dns问题 http://iphone.91.com/tutorial/syjc/140509/21686339.html 网络问题 手机4g开wifi,上传提交多次 时间问题 东八区下午6点上架成功 ...

  7. Shift-Invariant论文笔记

    ICML 2019 Making Convolutional Networks Shift-Invariant Again ICML 2019 Making Convolutional Network ...

  8. velocity生成静态页面代码

    首先需要必备的jar包: web.xml <!-- load velocity property --> <servlet> <servlet-name>veloc ...

  9. shell脚本,awk实现行列转换

    [root@localhost study]# cat file 张三 语文 张三 数学 李四 语文 李四 数学 王五 语文 王五 数学 王五 英语 怎么实现为下面的排序??? 语文 数学 语文 数学 ...

  10. Spring框架中的aop操作之一 及aspectjweaver.jar与aopalliance-1.0.jar下载地址 包含beans 注解context 和aop的约束

    (aspect oriented programming面向切面编程) 首先在原有的jar包: 需Spring压缩包中的四个核心JAR包 beans .context.core 和expression ...