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 卡特兰数,链接是一个不错的介绍卡特兰相关题目的博客。
http://blog.163.com/lz_666888/blog/static/1147857262009914112922803/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 100
#define BASE 10000
void multiply(int a[],int Max,int b) //大数乘法,注意参数的传递
{
int i,array=0;
for (i = Max-1; i >= 0; i--)
{
array += b * a[i];
a[i] = array % BASE; // 数组每一位存放大数的四位数字
array /= BASE;
}
}
void divide(int a[], int Max, int b) //模拟大数除法
{
int i, div = 0;
for (i = 0; i < Max; i++)
{
div = div * BASE + a[i];
a[i] = div / b;
div %= b;
}
}
int main()
{
int a[101][MAX],i, n;
memset(a[1],0,MAX*sizeof(int));
for (i=2, a[1][MAX-1] = 1; i < 101; i++) // 高坐标存放大数低位
{
memcpy(a[i], a[i-1], MAX * sizeof(int)); //h[i] = h[i-1];
multiply(a[i], MAX, 4 * i - 2); //h[i] *= (4*i-2);
divide(a[i], MAX, i + 1); //h[i] /= (i+1);
}
while (cin >> n&&n!=-1)
{
for (i = 0; i < MAX && a[n][i] == 0; i++); //去掉数组前为0的数字。
cout << a[n][i++]; //输出第一个非0数
for (; i < MAX; i++)
{
printf("%04d",a[n][i]); //输出后面的数,并每位都保持4位长度!(32767)
}
cout << endl;
}
return 0;
}

  

poj_2084_Game of Connections的更多相关文章

  1. 解决mysql too many connections的问题

    由于公司服务器上的创建的项目太多,随之创建的数据库不断地增加,在用navicat链接某一个项目的数据库时会出现too many connections ,从而导致项目连接数据库异常,致使启动失败. 为 ...

  2. Data source rejected establishment of connection, message from server: "Too many connections"解决办法

    异常名称 //数据源拒绝从服务器建立连接.消息:"连接太多" com.MySQL.jdbc.exceptions.jdbc4.MySQLNonTransientConnection ...

  3. Configure Security Settings for Remote Desktop(RDP) Services Connections

    catalogue . Configure Server Authentication and Encryption Levels . Configure Network Level Authenti ...

  4. 问题解决:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

    错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...

  5. Too Many Connections: How to Increase the MySQL Connection Count To Avoid This Problem

    1.问题描述 在启动使用mysql数据库的项目时,遇到一个报错,如下: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConn ...

  6. Configure the max limit for concurrent TCP connections(转)

    To keep the TCP/IP stack from taking all resources on the computer, there are different parameters t ...

  7. 打开mysql时,提示 1040,Too many connections

    打开mysql时,提示 1040,Too many connections,这样就无法打开数据库,看不了表里边的内容了. 出现这个问题的原因是,同时对数据库的连接数过大,mysql默认的最大连接数是1 ...

  8. mysql连接数设置操作(Too many connections)

    mysql在使用过程中,发现连接数超了~~~~ [root@linux-node1 ~]# mysql -u glance -h 192.168.1.17 -pEnter password: ERRO ...

  9. Too many connections解决方案

    原因:  my.ini 中设定的并发连接数太少或者系统繁忙导致连接数被占满. 连接数超过了 MySQL 设置的值,与 max_connections 和 wait_timeout  都有关. wait ...

随机推荐

  1. scss-嵌套规则

    在编写css代码的时候,可能由于嵌套的原因,需要多次重复书写选择器. 代码如下: #content article h1 { color: #333 } #content article p { ma ...

  2. Linux中怎么从root用户切换到普通用户

    su是在用户间切换,可以是从普通用户切换到root用户, test@ubuntu:~$ su Password:  root@ubuntu:/home/test# 也可以是从root用户切换到普通用户 ...

  3. 检查你要加入到gradle的第三方library是否是最新版本

    开发者从博客.github readme  或者 官方文档中找到如何在gradle 文件中加入dependency  的时候,往往版本已经比较老旧了,想要找到最新版,介绍一个利器 http://gra ...

  4. 修改mysql编码方式

    第一种:     通过mysql命令行修改: 1)首先查看数据库字符编码,命令为: show variables like’collation_%’; show variables like’char ...

  5. Azure 11 月新公布

    Azure 11 月新发布:Apple FairPlay Streaming, 应用服务(App Service), 虚拟机规模集(VMSS) Azure 媒体服务的 Apple FairPlay S ...

  6. numpy cheat sheet

    numpy cheat sheet https://files.cnblogs.com/files/lion-zheng/Numpy_Python_Cheat_Sheet.pdf

  7. sql 2008 远程过程调用失败 0x800706be

    啊哦,SQL Server挂了!sql 2008 远程过程调用失败 0x800706be,找了一下解决方案,如下: 1.打开控制面板->添加删除程序 2.卸载一个叫Microsoft SQL S ...

  8. 每天一个linux命令(21):chgrp,chown,chmod

    这三个命令都是改变文件属性与权限的,就放一起写了 charp:改变文件所属用户组 chown:改变文件所属者 chmod:改变文件的权限 一个文件对于owner,group ,others有不同的权限 ...

  9. Android(java)学习笔记51:ScrollView用法

    1. 理论部分 (1)ScrollView和HorizontalScrollView是为控件或者布局添加滚动条 (2)上述两个控件只能有一个孩子,但是它并不是传统意义上的容器 (3)上述两个控件可以互 ...

  10. python:类与对象命名空间、面对对象的组合用法

    1,类里可以定义两种属性: #静态属性 #静态属性就是直接在类中定义的变量 #动态属性 #动态属性就是定义在类中的方法 class Course: language = ['Chinese']#静态属 ...