poj_2084_Game of Connections
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 卡特兰数,链接是一个不错的介绍卡特兰相关题目的博客。
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的更多相关文章
- 解决mysql too many connections的问题
由于公司服务器上的创建的项目太多,随之创建的数据库不断地增加,在用navicat链接某一个项目的数据库时会出现too many connections ,从而导致项目连接数据库异常,致使启动失败. 为 ...
- Data source rejected establishment of connection, message from server: "Too many connections"解决办法
异常名称 //数据源拒绝从服务器建立连接.消息:"连接太多" com.MySQL.jdbc.exceptions.jdbc4.MySQLNonTransientConnection ...
- Configure Security Settings for Remote Desktop(RDP) Services Connections
catalogue . Configure Server Authentication and Encryption Levels . Configure Network Level Authenti ...
- 问题解决: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 ...
- Too Many Connections: How to Increase the MySQL Connection Count To Avoid This Problem
1.问题描述 在启动使用mysql数据库的项目时,遇到一个报错,如下: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConn ...
- 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 ...
- 打开mysql时,提示 1040,Too many connections
打开mysql时,提示 1040,Too many connections,这样就无法打开数据库,看不了表里边的内容了. 出现这个问题的原因是,同时对数据库的连接数过大,mysql默认的最大连接数是1 ...
- mysql连接数设置操作(Too many connections)
mysql在使用过程中,发现连接数超了~~~~ [root@linux-node1 ~]# mysql -u glance -h 192.168.1.17 -pEnter password: ERRO ...
- Too many connections解决方案
原因: my.ini 中设定的并发连接数太少或者系统繁忙导致连接数被占满. 连接数超过了 MySQL 设置的值,与 max_connections 和 wait_timeout 都有关. wait ...
随机推荐
- Java ConcurrentHashMap的小测试
今天正式开始自己的分布式学习,在第一章介绍多线程工作模式时,作者抛出了一段关于ConcurrentHashMap代码让我很是疑惑,代码如下: public class TestClass { priv ...
- Jedis Cluster源码分析
最近一个项目用到Jedis客户端,需要对这个客户端进行改造.看了一下Jedis Cluster源码,做个记录 首先,说核心内容, 在Jedis源码中,关于cluster有个两个重要的map.一个是no ...
- poj 1655 树的重心 && define注意事项
http://blog.csdn.net/acdreamers/article/details/16905653 题意:给定一棵树,求树的重心的编号以及重心删除后得到的最大子树的节点个数size,如果 ...
- vim-plug
vim包管理器vim-plug 安装 curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent. ...
- 集合之equals与hashCode方法
一 equals equals方法是Object级的,默认对比两个对象的内存地址,很多类都重写了该方法,对比对象的实际内容,一般对比同一类对象相同属性的属性值是否相同. 二 hashCode 1.哈 ...
- JavaScript彻底搞懂apply和call方法
彻底搞懂JavaScript中的apply和call方法 call和apply都是为了改变某个函数运行的context上下文而存在的,即为了改变函数体内部this的指向.因为JavaScript的函数 ...
- ArcGIS Engine从服务器(ArcSDE geodatabases)读取数据
从远程服务器读取数据进行处理,直接贴代码: public class ConnectDB { private static String SERVER = "xxx.xxx.xxx.xxx& ...
- python 后台运行命令
nohup python a.py > a.log 2>&1 & 在窗口中单开虚拟session: tmux new -s "name" 推出虚拟窗口 ...
- 学习笔记-java 集合
背景: 看的是<java核心技术 第8版>,覆盖jdk1.6.主要是对集合全局和细节进行全面掌握,较深入的理解集合.本人对java比较熟悉,但是对于细节的理解不深,知识点还不全,这是知识的 ...
- P2PSearcher云点播设置和使用技巧
P2PSearcher是一款基于ED2K网络的资源搜索工具,资源丰富,小巧轻便.资源搜索结果最丰富.智能排序定位精准,立即找到想要的资源.新版可突破服务器封杀限制,一个能用的P2PSearcher.整 ...