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 ...
随机推荐
- ef linq 查询某时间段内数据 踩的坑
var now = DateTime.Now;var list =db.Jinbi_TypeLimit.Where(x => x.IsAvailable && x.JinbiTy ...
- Java集合篇四:Map的基本应用
package com.test.collection; import java.util.HashMap; import java.util.Hashtable; import java.util. ...
- Highcharts error #14: www.highcharts.com/errors/14
错误原因:数据类型错误,需要的是Number类型,传入的却是String 以为为官网说明: Highcharts Error #14 String value sent to series.data, ...
- 01_Quartz基础结构
[各种任务调度的使用场景] 论坛每天凌晨统计论坛用户的积分排名. 论坛每半个小时生成精华文章. 每隔30分钟对锁定过期的用户解锁. 每月1号统计上个月各部门的业务数据. [Quartz 简介] Qua ...
- Qt之QSS(Q_PROPERTY-原始属性)
http://blog.csdn.net/liang19890820/article/details/51698536 版权声明:进步始于交流,收获源于分享!纯正开源之美,有趣.好玩.靠谱...作者: ...
- Business Component(BC)和Business Object(BO)
Siebel应用架构的一个成功的地方就是在应用里引入了BC,BO的概念,从而使得几千张关系数据表能够按照业务的含义组织成业务对象,对于业务人员而言具有了业务上的含义,而不仅仅是从技术人员的观点来对待数 ...
- synchronized(this)、synchronized(class)与synchronized(Object)的区别
在多线程开发中,我们经常看到synchronized(this).synchronized(*.class)与synchronized(任意对象)这几种类型同步方法.但是是否知道这几种写法有什么区别了 ...
- bash: ./adb: No such file or directory
运行adb出现这种错误: bash: ./adb: No such file or directory 但adb确实存在. 可能1.你用的是64位的Linux,没装32位运行时库,安装 $ sud ...
- 编译安装PHP开发环境
Linux 系统为 CentOS 7.2 1. 安装 Nginx 安装 Nginx 依赖包: # yum -y install zlib zlib-devel openssl openssl-deve ...
- umlの类图
版权声明:本文为博主原创文章,若要转载请注明出处!^_^ https://blog.csdn.net/u010892841/article/details/24844825 类图class diagr ...