(Catalan数 大数) Game of Connections poj2084
Language:
Game of Connections
|
Time Limit: 1000MS |
Memory Limit: 30000K |
|
Total Submissions: 8837 |
Accepted: 4358 |
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
用java,卡特兰数
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) { //java的基础部分要好好扎实。
Scanner in=new Scanner(System.in);
BigInteger a[]=new BigInteger[101];
a[0]=BigInteger.valueOf(0);
a[1]=BigInteger.valueOf(1);
int n;
while(in.hasNextInt()) {
n=in.nextInt();
if(n==-1)
break;
for(int i=2;i<=n;i++) {
a[i]=a[i-1].multiply(BigInteger.valueOf(i*4-2)).divide(BigInteger.valueOf(i+1));
}
System.out.println(a[n]);
}
}
}
(Catalan数 大数) Game of Connections poj2084的更多相关文章
- (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【集训笔记】【大数模板】特殊的数 【Catalan数】【HDOJ1133【HDOJ1134【HDOJ1130
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3324 http://blog.csdn.net/xymscau/artic ...
- 求解Catalan数,(大数相乘,大数相除,大数相加)
Catalan数 卡塔兰数是组合数学中一个常在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰(1814–1894)命名.历史上,清代数学家明安图(1692年-1763年)在其<割圜 ...
- HDU 1023 Train Problem II 大数打表Catalan数
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...
- HDU1023 Train Problem II【Catalan数】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目大意: 一列N节的火车以严格的顺序到一个站里.问出来的时候有多少种顺序. 解题思路: 典型 ...
- Catalan数应用整理
应用一: codevs 3112 二叉树计数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一个有n个结点的二叉树总共有 ...
- 【64测试20161112】【Catalan数】【数论】【扩展欧几里得】【逆】
Problem: n个人(偶数)排队,排两行,每一行的身高依次递增,且第二行的人的身高大于对应的第一行的人,问有多少种方案.mod 1e9+9 Solution: 这道题由1,2,5,14 应该想到C ...
- Catalan数(数论)
Catalan数 [参考网址]http://www.cnblogs.com/gongxijun/p/3232682.html 记得当时我们队写过一个,差点超时,现在找到了公式,感觉还是挺简单的. 还要 ...
- Catalan数 && 【NOIP2003】出栈序列统计
令h(1)=1, h(0)=1,catalan数满足递归式: h(n)=h(0)*h(n-1)+h(1)*h(n-2)+...+h(n-1)h(0) (n>=2) =C(2n, n)/(n+1) ...
随机推荐
- 《Linux内核设计与实现》读书笔记 3
第三章 进程管理 3.1进程 概念: 进程:处于执行期的程序.但不仅局限于程序,还包含其他资源(打开的文件,挂起的信号,内核内部数据,处理器状态,一个或多个具有内催音社的内存地址空间及一个或多个执行线 ...
- Beta版发布说明
我们的作品“校友聊”软件的最终版本于6月19日最终发布了,下面我们将对自己的产品进行介绍. 在使用之前,首先要进行用户注册,用户可以自行设置自己的账号,姓名,密码,签名,头像等信息,头像信息也可以在文 ...
- keras-VGG16 猫狗分类器
keras 原理: keras系列︱图像多分类训练与利用bottleneck features进行微调(三)https://blog.csdn.net/sinat_26917383/article/d ...
- 软件工程(五)UML
UML 统一建模语言,又称标准建模语言.是用来对软件密集系统进行可视化建模的一种语言.包括UML语义和UML表示法两个元素. UMl图由事物和关系组成,事物:UML模型中最基本的构成元素,是具有代表性 ...
- book项目分析
需求1:用户注册 需求如下: 1)访问注册页面 2)填写注册信息,提交给服务器 3)服务器应该保存用户 4)当用户已经存在----提示用户注册 失败,用户名已存在 5)当用户不存在-----注册成功 ...
- centos7编译安装zabbix的错误
[Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through s ...
- 2017 浙大校赛 [Cloned]
https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namesp ...
- Kitematic - VirtualBox is not installed. Docker for windows 10
Kitematic - VirtualBox is not installed. Docker for windows 10 https://github.com/docker/kitematic/i ...
- IP config with netsh under windows
================================================= CHINAUNICOME.bat route delete 0.0.0.0 mask 0.0.0.0 ...
- 解决因为本地代码和远程代码冲突,导致git pull无法拉取远程代码的问题
一.问题 当本地代码和远程代码有冲突的时候,执行git pull操作的时候,会提示有冲突,然后直接终止本次pull,查了些资料没有找到强制pull的方式,但是可以使用如下方式解决. 二.解决思路 可以 ...