Game of Connections
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 8772   Accepted: 4324

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

Source

PS:卡特兰数在ACM中比较具体的使用例子有,1括号匹配的种数。2在栈中的自然数出栈的种数。3求多边形内三角形的个数。4,n个数围城圆圈,找不相交线段的个数。5给定n个数,求组成二叉树的种数,本题为第四种。
  h(n)=(4*n-2)/(n+1)*h(n-1).
代码:
 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的更多相关文章

  1. POJ 2084 Catalan数+高精度

    POJ 2084 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:42 * ...

  2. (组合数学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 ...

  3. POJ 2084 Game of Connections

    卡特兰数. #include<stdio.h> #include<string.h> ; ; void mul(__int64 a[],int len,int b) { int ...

  4. POJ 2084 Game of Connections(卡特兰数)

    卡特兰数源于组合数学,ACM中比较具体的使用例子有,1括号匹配的种数.2在栈中的自然数出栈的种数.3求多边形内三角形的个数.4,n个数围城圆圈,找不相交线段的个数.5给定n个数,求组成二叉树的种数…… ...

  5. poj——2084  Game of Connections

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8664   Accepted: 42 ...

  6. POJ 2084

    第一题组合数学题.可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理.(高精度) #include <cstdio> #include & ...

  7. 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) ( ...

  8. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  9. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

随机推荐

  1. MySQL慢查询分析工具pt-query-digest详解

    一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdu ...

  2. 赶集网mysql开发36条军规

    写在前面的话: 总是在灾难发生后,才想起容灾的重要性: 总是在吃过亏后,才记得曾经有人提醒过. (一)核心军规 (1)不在数据库做运算    cpu计算务必移至业务层: (2)控制单表数据量    i ...

  3. TP5.0搭建restful API 应用

    1.配置环境变量,如果没配置会显示如下错误. 配置方法 1)右键此电脑-> 属性-> 高级系统设置->环境变量->Path 2)在Path后加上php目录的名称 如:E:\PH ...

  4. 跨平台图表控件TeeChart使用教程:将图表数据导出为XML格式

    在开发者使用TeeChart进行开发的过程中,不管是在设计时或者运行时都可以使用的图表导出对话框将图表数据轻易地导出为XML格式: TeeChart最新版那下载地址 上图为TeeChart导出对话框的 ...

  5. .NET 自动内存管理(垃圾收集GC)

    自动内存管理(垃圾收集GC) 在面向对象的环境里, 要使用资源,必须为响应 的类型分配一定 的内存空间.下面是访问一个资源所需要的几个步骤: 1. 调用中间语言(IL)的newobj 指令.当我们用N ...

  6. Python 爬虫实战(二):使用 requests-html

    Python 爬虫实战(一):使用 requests 和 BeautifulSoup,我们使用了 requests 做网络请求,拿到网页数据再用 BeautifulSoup 解析,就在前不久,requ ...

  7. DirectX HLSL 内置函数

    Intrinsic Functions (DirectX HLSL) The following table lists the intrinsic functions available in HL ...

  8. [原创]在Windows Server 2019上配置NAS

    序言 此教程安装的都是最新版本的.由于是当NAS让它非常稳定的运行,所以能不安装的软件尽量不要安装. 一.准备工作 [更新系统] 没啥,就他喵想用个最新的. 右键点击开始键->设置->更新 ...

  9. centos6.5_64bit-kvm安装部署

    kvm部署安装   目录 kvm部署安装... 1 一.kvm部署... 1 1.关闭selinux和防火墙... 1 2.查看主机是否支持虚拟化... 1 3.安装kvm和其他虚拟化软件包... 1 ...

  10. 关于SAP UI5数据绑定我的一些原创内容

    如何查找SAP UI5官方关于数据绑定的文档: https://sapui5.hana.ondemand.com/ 点Documentation: Filter里输入data就能看到Data Bind ...