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

直接用这个公式就好了,但是这个题涉及大数的处理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. AmazeUI 保存浏览器数据 永久性

    //保存永久缓存数据function SaveAmuiStore(ItemName, ItemData){ if (window.localStorage) { var store = $.AMUI. ...

  2. IT兄弟连 JavaWeb教程 Servlet定义以及环境配置 BS程序和CS程序

    随着网络技术的不断发展,单机的软件程序已难以满足网络计算机的需求.为此,各种各样的网络程序开发体系结构应运而生.其中,运用最多的网络应用程序开发体系结构可以分为两种,一种是基于客户端/服务器的C/S结 ...

  3. window.close() 关闭当前浏览器页

    function eseFun() { var browserName = navigator.appName; //获取浏览器名称 if(browserName == "Netscape& ...

  4. Yslow使用方法

    Yslow是雅虎开发的基于网页性能分析浏览器插件,从年初我使用了YSlow后,改变了博客模板大量冗余代码,不仅提升了网页的打开速度,这款插件还帮助我分析了不少其他网站的代码,之前我还特意写了提高网站速 ...

  5. 【笨办法学Python】习题11:打印出改变了的输入

    print "How old are you?", age = raw_input() print "How tall are you?", height = ...

  6. 更改IDEA默认使用JDK1.5编译项目

    在使用IDEA编译项目时,总是提示我编译失败,有些功能是在1.5之后的版本才支持.废了好大的功夫才编译成功.下面呢,就是更改编译的过程了! 一.初步更改 使用快捷键Ctrl+Alt+Shift+S打开 ...

  7. VS远程调试虚拟机中的程序

    1.  设置VS项目属性 => 调试页   例子如下 远程命令: C:\test.exe 工作目录 : C:\ 远程服务器名称:  192.168.xx.xx  查看网络共享 => 本地连 ...

  8. COGS 1913. AC自动机

    ★★   输入文件:ACautomata.in   输出文件:ACautomata.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 对,这就是裸的AC自动机. 要求:在 ...

  9. HDU 4348 I - To the moon 可持续化

    队友套的可持续化线段树,徘徊在RE和MLE之间多发过的... 复用结点新的线段树平均要log2N个结点. 其实离线就好,按照时间顺序组织操作然后dfs. #include <iostream&g ...

  10. jQuery备忘录

    jquery 中遍历数组 var arr = [1,2,3,4,5] $.each(arr,function(i,j){ console.log(i,j) }) 结果 0 1 1 2 .... jQu ...