(组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)
package com.njupt.acm; import java.math.BigInteger;
import java.util.Scanner; public class POJ_2084 { public static void main(String[] args) {
BigInteger catalan[] = new BigInteger[102];
catalan[1] = new BigInteger("1"); BigInteger one = new BigInteger("1");
BigInteger two = new BigInteger("2");
BigInteger four = new BigInteger("4"); int i;
for(i = 1 ; i <= 100 ; ++i){ catalan[i+1] = catalan[i].multiply(four.multiply(new BigInteger(i + "")).subtract(two)).divide(new BigInteger(i + "" ).add(one)); } Scanner scanner = new Scanner(System.in);
int n ; while(true){
n = scanner.nextInt();
if(n < 0){
break;
} System.out.println(catalan[n + 1]);
} }
}
(组合数学3.1.2.2)POJ 2084 Game of Connections(卡特兰数公示的实现)的更多相关文章
- POJ 2084 Game of Connections 卡特兰数
看了下大牛们的,原来这题是卡特兰数,顺便练练java.递归式子:h(0)=1,h(1)=1 h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) ( ...
- POJ 2084 Game of Connections(卡特兰数)
卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...
- POJ 2084 Game of Connections
卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...
- POJ 2084 Catalan数+高精度
POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * ...
- uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)
option=com_onlinejudge&Itemid=8&category=471&page=show_problem&problem=4224" st ...
- CodeForces - 1204E Natasha, Sasha and the Prefix Sums (组合数学,卡特兰数扩展)
题意:求n个1,m个-1组成的所有序列中,最大前缀之和. 首先引出这样一个问题:使用n个左括号和m个右括号,组成的合法的括号匹配(每个右括号都有对应的左括号和它匹配)的数目是多少? 1.当n=m时,显 ...
- 组合数学 - 置换群的幂运算 --- poj CARDS (洗牌机)
CARDS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1448 Accepted: 773 Description ...
- (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)
/* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- (组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)
/* * POJ_1146.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
随机推荐
- Poj 2583 Series Determination
1.Link: http://poj.org/problem?id=2583 2.Content: Series Determination Time Limit: 1000MS Memory L ...
- Nodejs加密php解密
var crypto = require('crypto'); function decode(cryptkey, iv, secretdata) { var decipher = crypto.cr ...
- 在Linux环境下给php添加mbstring扩展
1,今天在开发项目的时候使用了一个php函数(mb_strcut),运行代码时候提示报错"call to undefind function mb_strcut",首先检查下函数名 ...
- Discuz x2.5 单页制作的教程
首先,单页包括该单页的php文件和该单页的模板(.htm)文件,比如:host.php.host.htm 单页的php文件内容如下: <?php require './source/class/ ...
- C# Winform程序请求管理员权限
如果你的Winform程序需要管理员权限才能正常执行,请加入如下代码: static class Program { /// <summary> /// 应用程序的主入口点. /// &l ...
- ARCGIS 10中添加excel点字段生产点shp文件的工具
菜单栏中——文件——添加数据——添加XY数据——选择excel。 选择x,y和投影(注意这里投影应该是原数据的本身投影,不能直接选择你要转换的投影)完成。
- MenuItem
private void 文件ToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("打开测试" ...
- 【NHibernate】HQL入门
在NHibernate 中 HQL 可以帮我们转成最终依赖数据库的查询脚本: 语法也甚是强大,适配主流数据库, HQL不支持union,要想取多个表数据可以做两次单独查询. IQuery query ...
- linux编程之指针
这个是数组指针.指针数组.二维数组之间相互转换的代码 #include<stdio.h> void main() { ][]={,,,,,,,}; int *b=NULL; int **c ...
- poj 2762 Going from u to v or from v to u?(强连通分量+缩点重构图+拓扑排序)
http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS Memory Limit: ...