题意:将1~2n个数依照顺时针排列好。用一条线将两个数字连接起来要求:线之间不能有交点。同一个点仅仅同意被连一次。

最后问给出一个n,有多少种方式满足条件。

分析:

ans[n]表示n的中的种类数。 规定ans[0] = ans[1] = 1;

如果给出的数是n那么从1開始, 与1之间相连的数与1之间间隔的对数各自是0, 1, 。。n-1, 那么我们就能够将他们切割成两部分,对于每一部分我们分别将其的结果求出,之后再相乘就是间隔对数s(s是0, 。。

n-1)的总的种类数。

最后我们能够总结出ans[n] = ans[0]*ans[n-1]+ans[1]*ans[n-2]+...ans[n-1]*ans[0];即为卡特兰数。

如果给出的是4。那么一共同拥有8个数。依照顺时针排列,我们如果从1開始,那么1能够与2(之间相差0个数), 4(之间相差2个数), 6(之间相差4个数), 8(之间相差6个数)。假如我们知道相差n个数的的种类数,那么我们仅仅须要将他们相加。即为我们所要求的总种类数。

以下我就依照上面的样例即n=4分析一下。

相差为0的时候,我们仅仅须要考虑剩下的三对就可以。则相差为0的种类数就为ans[3]*ans[0],之间相差2的时候我们就吧原有的序列分成了两部分,第一部分仅仅有2个数。第二部分有4个数。那么相差为2的种类数就是ans[2]*ans[1];相差为4的事实上就是上面情况的第一部分和第二部分颠倒了,这样的情况下的种类数是ans[1]*ans[2],相差为6就是第一种情况的颠倒,所以种类数是ans[3]*ans[0];

代码:

#include <cstdio>
#include <cstring>
int ans[102][100]; void table(){
ans[0][0] = ans[1][0] = 1;
int i, j;
for(i = 2; i < 102; i ++){
int c = 0;
for(j = 0; j < 100; j ++){
ans[i][j] = ans[i-1][j]*(4*i-2)+c;
c = ans[i][j]/10;
ans[i][j] %= 10;
}
int z = 0;
for(j = 99; j >= 0; j --){
z= z*10+ans[i][j];
ans[i][j] = z/(i+1);
z %= (i+1);
}
}
}
int main(){
table();
int temp;
while(scanf("%d", &temp), temp != -1){
int i = 99;
while(ans[temp][i] == 0) i --;
while(i >= 0) printf("%d", ans[temp][i]), i--;
printf("\n");
}
return 0;
}

题目链接:

pid=164">http://acm.nyist.net/JudgeOnline/problem.php?pid=164

     http://poj.org/problem?id=2084

nyoj 164&amp;&amp;poj2084 Game of Connections 【卡特兰】的更多相关文章

  1. POJ2084 Game of Connections 卡特兰数 关于卡特兰数经典的几个问题

    Game of Connections Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9128   Accepted: 44 ...

  2. [POJ2084]Game of Connections

      Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7888   Accepted: 3965 Description Thi ...

  3. POJ2084 Game of Connections(数学,dp)

    题目链接. 分析: 简单的 Catalan 数 将x~y编号,设解为 d(x, y), d(x, y) = {d(x+1,i-1)*d(i+1,y)}, 其中 x+1<= i  <= y, ...

  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. (Catalan数 大数) Game of Connections poj2084

    Language: Game of Connections Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8837 Accept ...

  7. How to enable remote connections to SQL Server

    <img src="https://miro.medium.com/max/1400/1*18lrHvJ8YtADJDT7hxIThA.jpeg" class="g ...

  8. NYOJ 1007

    在博客NYOJ 998 中已经写过计算欧拉函数的三种方法,这里不再赘述. 本题也是对欧拉函数的应用的考查,不过考查了另外一个数论基本定理:如何用欧拉函数求小于n且与n互质所有的正整数的和. 记eule ...

  9. NYOJ 998

    这道题是欧拉函数的使用,这里简要介绍下欧拉函数. 欧拉函数定义为:对于正整数n,欧拉函数是指不超过n且与n互质的正整数的个数. 欧拉函数的性质:1.设n = p1a1p2a2p3a3p4a4...pk ...

随机推荐

  1. 深度学习国外课程资料(Deep Learning for Self-Driving Cars)+(Deep Reinforcement Learning and Control )

    MIT(Deep Learning for Self-Driving Cars) CMU(Deep Reinforcement Learning and Control ) 参考网址: 1 Deep ...

  2. master..xp_fileexist

    declare @sql varchar(800) set @sql='E:\temp.dbf'create table #tb(a bit,b bit,c bit)   insert into #t ...

  3. 整理一下关于Crypto加密的坑

    之前写接口一般不用加密(做了权限处理),最近公司要求接口加密,我开始了入坑之路 因为公司其他人用的AES和DES加密,我就在网上查了下关于这方面的使用方法. 首先安装Crypto pip instal ...

  4. PHP性能调优---php-fpm - 启动参数及重要配置详解

    约定几个目录/usr/local/php/sbin/php-fpm/usr/local/php/etc/php-fpm.conf/usr/local/php/etc/php.ini 一,php-fpm ...

  5. 简单实现textview文本每隔两秒就改变一次

    //这个方法可以实现文本每隔两秒就改变一次, public void textTask(){ final android.os.Handler handler=new android.os.Handl ...

  6. CentOS 7.2 下 PXE+kickstart 自动安装系统

    一.简单概述 1.1 Kickstart 概述 对于网络安装系统,在linux 下面最熟悉的应该就是 Kickstart 以及 cobbler.写这篇文章的目的在于我公司目前使用的就是 Kicksta ...

  7. xmanager

    [root@upright91 run]# ./runBenchmark.sh updbtpcc.properties sqlTableCreates Exception in thread &quo ...

  8. Ubuntu16.04下Hive的安装与配置

    一.系统环境 os : Ubuntu 16.04 LTS 64bit jdk : 1.8.0_161 hadoop : 2.6.4mysql : 5.7.21 hive : 2.1.0 在配置hive ...

  9. rabbitmq学习之路-rabbitmqctl

    rabbitmqctl使用 学习rabbitmq,原理之后第一个要掌握的就是rabbitmqctl这个命令的用法了,rabbitmq的管理功能最全的就是rabbitmqctl命令了,当然还有HTTP ...

  10. 【SQL】182. Duplicate Emails

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...