POJ 2084 Catalan
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 8772 | Accepted: 4324 |
Description
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
You may assume that 1 <= n <= 100.
Output
Sample Input
2
3
-1
Sample Output
2
5
Source
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int t;
BigInteger f[]=new BigInteger[1005];
f[1]=BigInteger.valueOf(1);
f[2]=BigInteger.valueOf(2);
f[3]=BigInteger.valueOf(5);
for(int i=4;i<=100;i++){
BigInteger a=BigInteger.valueOf(4*i-2);
BigInteger b=BigInteger.valueOf(i+1);
f[i]=a.multiply(f[i-1]).divide(b);
}
while(cin.hasNextInt())
{
t=cin.nextInt();
if(t==-1) break;
System.out.println(f[t]);
}
}
}
POJ 2084 Catalan的更多相关文章
- POJ 2084 Catalan数+高精度
POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * ...
- (组合数学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 ...
- POJ 2084 Game of Connections
卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...
- POJ 2084 Game of Connections(卡特兰数)
卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...
- poj——2084 Game of Connections
Game of Connections Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8664 Accepted: 42 ...
- POJ 2084
第一题组合数学题.可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理.(高精度) #include <cstdio> #include & ...
- 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 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- JavaScript new 操作符 OOP(一)
什么是对象 对象是单个实物的抽象,通常需要一个模板,表示某一类实物的共同特征,然后对象根据这个模板生成. 对象是一个容器,封装了属性(property)和方法(method),属性是对象的状态, ...
- Dreams save us. Dreams lift us up and transform us into something better.
Dreams save us. Dreams lift us up and transform us into something better.梦想能够拯救我们.梦想能够激励我们并让我们成为更好的人 ...
- 绘图之Canvas学习
一 Canvas的用法 博客:http://blog.taorenjia.com/?p=237 1.drawCircle(float cx, float cy, float radius, ...
- AWS ELB Sticky Session有问题?别忘了AWSELB cookie
我们的产品中有两个Module,分别部署在独立的Linux机器上,Module 1需要向Module 2发起Http请求来获得服务.由于Module 2有多台,因此我们会在Module 2前部署一台负 ...
- hibernate_HelloWorld
环境准备 1.下载 hibernate 3.3.2: 2.下载 hibernate 3.4.0: 3.注意阅读 hibernate compatibility matrix(hibernate 网站, ...
- selenium找不到元素
1.页面元素处于不显示状态时,找不元素.必须使元素处于显示状态.使用js 或者 元素的点击事件等方式可以实现. " src="index.php?m=Index&a=Men ...
- redhat7.3忘记root密码后如何重置root密码
redhat7系如果忘记root密码,重置密码方法与redhat6系不同! 1.开机启动系统,在grub选择启动内核项时 按‘e’进入编辑模式 2.这时看到的参数并不全,要按上下键滚动显示, 3.在l ...
- 笨办法学Python(十八)
习题 18: 命名.变量.代码.函数 标题包含的内容够多的吧?接下来我要教你“函数(function)”了!咚咚锵!说到函数,不一样的人会对它有不一样的理解和使用方法,不过我只会教你现在能用到的最简单 ...
- TP5.1 配置的获取与设置
我们现在学习对配置文件的获取(Config::get)与设置(Config::set) 我们将学会: (1)获取到一级配置文件 (2)获取到二级配置文件 (3)设置二级配置文件 1.获取一级配置文件 ...
- CRUD全栈式编程架构之控制器的设计
页面 这里界面我采用jquery miniui来做的,当你完全了解了整个设计之后可以轻松切换到其他的js框架,个人认为类似muniui,easyui等等这类可以将web界面做得和winform类似的框 ...