Problem 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
 
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int n;
#define BASE 10000
#define UNIT 4
#define FORMAT "%04d" class BigNum{
public:
int a[20];
int length;
BigNum(const int k){ //用小于BASE的k初始化大数
memset(a, 0, sizeof(a));
a[0] = k;
length = 1;
}
BigNum(){
memset(a, 0, sizeof(a));
length = 0;
}
BigNum operator * (const BigNum & B){
BigNum ans;
int i,j,up=0,num;
for(i=0; i<length; i++){
up = 0; //每次循环都要初始化为0
for(j=0; j<B.length; j++){
num = up + a[i] * B.a[j] + ans.a[i+j];
up = num / BASE;
num = num % BASE;
// cout << num << endl;
ans.a[i+j] = num;
}
// cout << up << endl;
if(up > 0)
ans.a[i+j] = up;
}
ans.length = i+j;
while(ans.a[ans.length -1] == 0 && ans.length > 1)
ans.length--;
return ans;
}
BigNum operator /(const int & k) const{ // k < BASE, 对此题适用
BigNum ans;
int down=0,i,num;
for(i=length-1; i>=0; i--){
num = ( (down * BASE) + a[i] ) / k;
down = ( (down * BASE) + a[i] ) % k;
ans.a[i] = num;
}
ans.length = length;
while(ans.a[ans.length-1] == 0 && ans.length > 1)
ans.length -- ;
return ans;
}
void print(){
printf("%d", a[length-1]);
for(int i=length-2; i>=0; i--)
printf(FORMAT,a[i]);
}
}; //f(n) = C(2n,n)/(n+1)
int main(){
BigNum nums[101];
nums[1] = BigNum(1);
nums[2] = BigNum(2);
nums[3] = BigNum(5);
for(int i=4; i<=100; i++){
nums[i] = nums[i-1] * (4*i-2)/(i+1);
}
int n;
while(scanf("%d", &n), n>0){
nums[n].print();
printf("\n");
}
return 0;
}

HDU 1134 卡特兰数 大数乘法除法的更多相关文章

  1. 2014年百度之星程序设计大赛 - 初赛(第一轮) hdu Grids (卡特兰数 大数除法取余 扩展gcd)

    题目链接 分析:打表以后就能发现时卡特兰数, 但是有除法取余. f[i] = f[i-1]*(4*i - 2)/(i+1); 看了一下网上的题解,照着题解写了下面的代码,不过还是不明白,为什么用扩展g ...

  2. hdu-1130(卡特兰数+大数乘法,除法模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130 卡特兰数:https://blog.csdn.net/qq_33266889/article/d ...

  3. hdu 1130,hdu 1131(卡特兰数,大数)

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. HDU 1134 Game of Connections(卡特兰数+大数模板)

    题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 20 ...

  5. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  7. hdu 1023 卡特兰数《 大数》java

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. Buy the Ticket HDU 1133 卡特兰数应用+Java大数

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  9. 【hdoj_1133】Buy the Ticket(卡特兰数+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元 ...

随机推荐

  1. tomcat优化-有改protocol 和 缓存 集群方案

    tomcat优化 在线上环境中我们是采用了tomcat作为Web服务器,它的处理性能直接关系到用户体验,在平时的工作和学习中,归纳出以下七种调优经验. 1. 服务器资源 服务器所能提供CPU.内存.硬 ...

  2. [转]openlayer+geoserver实现WFS操作

    From:http://liushaobo2005.blog.163.com/blog/static/253056702011541462372/ wfs是OGC的标准规范,主要用于提供对矢量地理数据 ...

  3. PDF转word文档

    本文未对扫描版的PDF实验,但是可编辑PDF版本可以转换为word而且转换后的word是可编辑的. 1.从http://xiazai.zol.com.cn/detail/33/326858.shtml ...

  4. hdu 1300 Pearls(dp)

    Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  5. 高性能浏览器网络(High Performance Browser Networking) 第二章

    第2章 TCP篇 互联网的核心是两个协议,IP和TCP. IP也叫Internet协议,提供主机到主机的路由和寻址:TCP,传输控制协议,在不可靠的传输通道上提供一个可靠的网络抽象.TCP / IP协 ...

  6. PHP高级特性基础

    php对象在内存中的区域:php对象名和对象存放的位置是不一样的,这一点和java是一模一样的,所以在php面向对象部分你完全可以套用java的思想去做.对象存放在堆区(heap)而对象名则和其他普通 ...

  7. Swift String 一些常用方法

    //字符串 //1 判断字符串是否为空 var test1Str="" var test1Str2:String = String(); println("test1St ...

  8. 关于常用meta的总结

    入行也半年了,无数次的想过写博客也无数次的想过第一篇会写什么,一直没有落实.今天心血来潮把博客开了,那就写点东西吧.第一篇就写一写看似简单但又经常不注意到的meta标签吧.(博主经验尚浅,有许多理解不 ...

  9. Android学习之菜单

    android中包含多种菜单,本例带来的是选项菜单和上下文菜单. 1.选项菜单 在android中,开发者可以在xml文档中部署所要添加的菜单,在后台调用即可. <menu xmlns:andr ...

  10. Android环境开发搭建

    今天第一次接触安卓,从开发环境的配置到程序的运行,足足搞了一天,也没有整出来. 1.安装JDK 在JDK官网上下载了最新的JDK,安装成功后进行环境的配置.JAVA_HOME:C:\Program F ...