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. 只有勇敢的人、鲁莽的人和绝望的人才会追求大的变革 – D.J. Anderson

    只有勇敢的人.鲁莽的人和绝望的人才会追求大的变革 – D.J. Anderson http://www.cnblogs.com/lchrennew/p/Why-The-Future-Of-Agile- ...

  2. SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET

    SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET SAE利用storge上传文件

  3. jquery获取复选框

    Html代码: <input type="checkbox" name="chekItem" /> checkbox1 <br /> & ...

  4. OC基础2:一些基本概念

    "OC基础"这个分类的文章是我在自学Stephen G.Kochan的<Objective-C程序设计第6版>过程中的笔记. 1.字符常量是存放在单引号中的单个字符,字 ...

  5. docker学习笔记(1)

    (1)Docker介绍 关于Docker的介绍,我就不列举出来了.到百度.谷歌搜索.非常多介绍文章.以下我给出官网的介绍:https://www.docker.com/whatisdocker/ (2 ...

  6. UML视图(四)状态图

    以下是一个图书馆管理系统的状态图,非常典型,涵盖状态图的全部元素的使用,由于状态图相对照较简单,直接从看图就能非常好地掌握.假设想对状态图的元素严谨的概念进行了解,在图下方,有仔细的叙述. 看了上面的 ...

  7. uva 10161 Ant on a Chessboard 蛇形矩阵 简单数学题

    题目给出如下表的一个矩阵: (红字表示行数或列数) 25 24 23 22 21 5 10 11 12 13 20 9 8 7 14 19 3 2 3 6 15 18 2 1 4 5 16 17 1 ...

  8. 模块化利器:RequireJS常用知识

    1. 模块化 目前常见的模块化开发方式,全局空间方式是最基本的一种,另外常见的还有遵循AMD规范的开发方式,遵循CMD规范的开发方式,和ECMAScript 6的开发方式.需要说明的是,CMD和ES6 ...

  9. C#获取变量名的扩展方法

    // </summary> /// <param name="var_name"></param> /// <param name=&qu ...

  10. c#变量在for循环内声明与外的区别

    1.这样写是错误的 #region 有这样的一个字符串类型的数组{"老杨","老苏","老马","老牛"};要求 变换成 ...