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

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

题目大意:一圆环上有2n个点,求两两连线且不交叉的方法数。
思路:
卡特兰数
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;
int n,len,tmp,sum,b[N],a[N][N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int catelan()
{
    len=; a[][]=b[]=;
    ;i<;i++)
    {
        ;j<len;j++)
         a[i][j]=a[i-][j]*(i*-);
        sum=;
        ;j<len;j++)
        {
            tmp=sum+a[i][j];
            a[i][j]=tmp%;
            sum=tmp/;
        }
        while(sum)
        {
            a[i][len++]=sum%;
            sum/=;
        }
        ;j>=;j--)
        {
            tmp=sum*+a[i][j];
            a[i][j]=tmp/(i+);
            sum=tmp%(i+);
        }
        ])
         --len;
        b[i]=len;
    }
}
int main()
{
    catelan();
    )
    {
        n=read();
        ) break;
        ;i>=;i--)
         printf("%d",a[n][i]);
        printf("\n");
    }
    ;
}

poj——2084  Game of Connections的更多相关文章

  1. POJ 2084 Catalan数+高精度

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

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

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

  3. POJ 2084 Game of Connections

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

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

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

  6. POJ 2084 Catalan

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

  7. poj——2367  Genealogical tree

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6025   Accepted: 3969 ...

  8. POJ 2084

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

  9. Poj 2796 单调栈

    关于单调栈的性质,和单调队列基本相同,只不过单调栈只使用数组的尾部, 类似于栈. Accepted Code: /******************************************* ...

随机推荐

  1. 生成自签名ca 证书 使nginx 支持https

    创建服务器私钥,命令会让你输入一个口令:$ openssl genrsa -des3 -out server.key 1024创建签名请求的证书(CSR):$ openssl req -new -ke ...

  2. 385 Mini Parser 迷你解析器

    Given a nested list of integers represented as a string, implement a parser to deserialize it.Each e ...

  3. 《编写可维护的Javascript》学习总结

    第一部分 一.基本规范 1.缩进:一般以四个空格为一个缩进. 2.语句结尾:最好加上分号,因为虽然“自动分号插入(ASI)”机制在没有分号的位置会插入分号,但是ASI规则复杂而且会有特殊情况发生 // ...

  4. VB.NET 小程序 4

    Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...

  5. scala-基础-映射(1)

    //映射(1)-构建,获取,更新,迭代,反转,映射(可变与不可变 互换) class Demo1 extends TestCase { //构建与获取 def test_create_^^(){ // ...

  6. python自动化--语言基础五面向对象、迭代器、range和切片的区分

    面向对象 一.面向对象简单介绍: class Test(): #类的定义 car = "buick" #类变量,定义在类里方法外,可被对象直接调用,具有全局效果 def __ini ...

  7. ASP MVC

    V-view 显示层 C-controller 控制层 M-model 模型 D-database 数据库 S-Service 服务 D-Database/Dao 数据库/访问数据库的方法 View即 ...

  8. 6.11 将分割数据转换为多值IN列表

    问题 已经有了分隔数据,想要将其转换为WHERE子句IN列表中的项目.考虑下面的字符串: 7654,7698,7782,7788 要将该字符串用在WHERE子句中,但是下面的SQL语句是错误的,因为E ...

  9. 10.5 集合ArrayList 和 io流

    1.ArrayListToFile package day10_io_fileWrite_Read.arraylist_tofile; import java.io.BufferedWriter; i ...

  10. spring用来干什么,解决的问题

    // 1. 实体类 class User{ } //2. dao class  UserDao{ .. 访问db } //3. service class  UserService{ UserDao ...