(组合数学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 OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- swing读书笔记转载
(swing读书笔记)Swing Look And Feel(1) http://blog.csdn.net/cszhao1980/article/details/7343524 (swing读书笔记 ...
- [原创] linux课堂-学习笔记-目录及概况
本学习笔记基于:网易云课堂-linux课堂 课时1Centos 6.4安装讲解46:14 课时2Centos 6.4桌面环境介绍与网络连接04:30 课时3 Linux目录结构介绍及内核与shell分 ...
- php学习日志(3)-echo&print
在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较. echo与print的区别: echo print 连续输出字符串 能连续输出多个字符串 只能输出一个字符串 ...
- WPF如何卸载U盘(弹出USB设备)
应用程序和硬件设备的通信过程是:应用程序使用CreateFile函数打开设备,然后用DeviceIoControl()与硬件设备通信. CreateFile函数: [DllImport("k ...
- 1067. Sort with Swap(0,*) (25)
时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given any permutation of the num ...
- 2014年辛星完全解读Javascript第六节 对象
随着面向对象的普及,现在很多语言都在支持面向对象,Javascript也不例外,所谓对象,就是拥有属性和方法的数据.这里的属性其实就是变量,这里的方法,其实就是函数.但是Javascript的面向对象 ...
- 在fedora 桌面上添加应用程序
在网上下了个android studio,这个程序只是的压缩包,解压后程序也只能在SHELL下敲入studio.sh才能运行 能不能向其他程序一样,在fedora桌面上找到应用程序,点击执行呢.在网上 ...
- EXTJS store 某行某列数据更新等操作
1.可以使用add(Ext.data.Record[] records)或者add(Ext.data.Record record)向store末尾添加一个或多个record.如: var newRec ...
- 在Hadoop分布式文件系统的索引和搜索
FROM:http://www.drdobbs.com/parallel/indexing-and-searching-on-a-hadoop-distr/226300241?pgno=3 在今天的信 ...