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

直接用这个公式就好了,但是这个题涉及大数的处理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. SourceGrid之Grid绑定数据

    private void BindData() { //为绑定的按钮选线增加单击事件 SourceGrid.Cells.Controllers.CustomEvents clickEvent = ne ...

  2. vue2.0:(二)、mock数据

    什么是mock数据呢?很多情况下,后台的搭建比起前端来说要麻烦的多,所以,常常是前端写好了页面以后后台接口却没有写好,但是在一个项目中,接口调试确实是最浪费时间的,所以,往往前端需要自己模拟数据. 第 ...

  3. 面向对象super内置函数(转)

    super函数用来解决钻石继承. 一.python的继承以及调用父类成员 父类: class Base(object): def __init__(self): print("base in ...

  4. 《Python基础教程》 读书笔记 第九章 魔法方法、属性和迭代器(上)

    构造方法 在Python中创建一个构造方法很容易.只要把init方法的名字从简单的init修改为魔法版本__init__即可: >>> class FooBar: ...     d ...

  5. 阿里云apt-get安装包时Err:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/main amd64 git amd64 1:2.7.4-0ubuntu1.2 404 Not Found

    新部署的云服务器出现如下错误: root@iZj6cbjalvhsw0fhndmm5xZ:~# apt-get install git Reading package lists... Done Bu ...

  6. 使用bat脚本调用py文件直接获取应用的包名和targetversion

    背景: 在上一篇已经介绍过如何利用python调用aapt获取包名 https://www.cnblogs.com/reseelei-despair/p/11078750.html 但是因为每次都要修 ...

  7. struts2的多个文件上传

                成功效果图:                 上篇文章描述了单个文件的上传和配置,下面主要讲解下不同的地方: index.jsp <head> <script ...

  8. oracle中group by的高级用法

    简单的group by用法 select c1,sum(c2) from t1 where t1<>'test' group by c1 having sum(c2)>100; ro ...

  9. PHP 头部utf-8

    只是自己用的一些存储,请各位看官大大勿怪. header("Content-Type: text/html;charset=utf-8"); 2019年04月10日

  10. 洛谷 P2872 道路建设

    https://www.luogu.org/problemnew/show/P2872 算是比较裸的并查集了,已经有路的两个点之间建一条代价为0的边,路径长度计算两点之间的距离,做并查集就好咯. #i ...