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

直接用这个公式就好了,但是这个题涉及大数的处理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. Linux用户管理-用户账号管理

    一.用户账号的增.删.改.查 1>添加用户------useradd 注:1.用户名不应是纯数字或者以数字开头 2.将登陆shell改为/sbin/nologin可禁止用户登录 格式:usera ...

  2. body和普通div背景图宽高百分比的区别

    body和普通div背景图的区别  background: url(//m.360buyimg.com/mobilecms/s220x220_jfs/t2746/167/831241799/29915 ...

  3. 《Head First HTML与CSS》项目实践中学到的东西

    1.组织的重要性. 首先是要建立两个根文件夹,一个存上线页面的资源,一个存测试页面的资源.所有改动内容都在测试页面的文件夹中进行,在这个文件夹中进行测试.W3C语法检测后(HTML检测网站:https ...

  4. sizeof()用法汇总 zhuan

    sizeof()功能:计算数据空间的字节数1.与strlen()比较      strlen()计算字符数组的字符数,以"\0"为结束判断,不计算为'\0'的数组元素.       ...

  5. shell中使用ssh

    ssh服务是不能用非交互的方式传递密码,想不输入密码,直接ssh连接到服务器有两种方法,sshpass和expect sshpass # wget http://downloads.sourcefor ...

  6. Selenium私房菜系列9 -- 我遇到的问题及解决问题的方法

    Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

  7. Azure 项目构建 – 部署 Jenkins 服务器以实现持续集成(CI)

    通过完整流程详细介绍了如何通过 Azure 虚拟机.虚拟网络等服务在 Azure 平台上快速搭建 Jenkins 服务器. 此系列的全部课程 https://school.azure.cn/curri ...

  8. watchguard 软件工程师内部招聘!

    作为watchguard正式员工,现发布公司最近的招聘信息,待遇优厚,请符合条件的朋友和我联系并将简历发给我,我会尽早联系公司人力部门. 我的邮件:daibao91888@163.com 博客:htt ...

  9. 异步 ThreadPool

    线程池是单例,一个进程里只有一个线程池 private void btnThreadPool_Click(object sender, EventArgs e) { Stopwatch watch = ...

  10. openstack No valid host was found. There are not enough hosts available.

    root@dell-PowerEdge-T30:~# gedit /var/log/nova/nova-conductor.logroot@dell-PowerEdge-T30:~# gedit /v ...