HDU 1134 卡特兰数 大数乘法除法
来源:互联网 发布:知乎护肤品各经典产品 编辑:程序博客网 时间:2024/05/16 06:30
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?
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
23-1
Sample Output
25
#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; //每次循环都要初始化为0for(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 卡特兰数 大数乘法除法
- HDU 1134 卡特兰数 大数乘法除法
- hdu-1134-Game of Connections(卡特兰数 大数乘法除法)
- HDU 1023 Train Problem II 卡特兰数 大数的乘法除法
- hdu 1130 How Many Trees?(卡特兰数,大数的乘法与除法)
- hdu 1134 卡特兰数+大数
- hdu 1134 卡特兰数(大数模板)
- HDU 1133 Buy the Ticket 50,100钱买票,大数乘除法,卡特兰数变形
- hdu 1134 Game of Connections 【卡特兰数+大数】
- hdu 1023+1030+1134 卡特兰数+大数模板处理
- HDU 1130(卡特兰数,大数)
- hdu 1023 大数 卡特兰数
- hdu 1023(大数+卡特兰数)
- hdu 1131 卡特兰数,大数
- HDOJ1023(卡特兰数+大数乘除法)
- 卡特兰数 大数
- 大数卡特兰数
- 大数卡特兰数
- kindsoft 文本编辑器 非常好用
- POJ 1129/ZOJ 1084
- 【win7系统登录QQ但是无法打开网页怎么办】
- source 命令解析
- 远景在线(www.pcbeta.com):使用IE10登陆中国银行网银蓝屏或者死机的解决方案
- HDU 1134 卡特兰数 大数乘法除法
- JavaScript常用内置对象(window、document、form对象)
- 操作表空间命令一系列
- 计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接
- .net 2007数据库性能分析(更新)
- HTTP状态码:常见的HTTP状态码有哪些
- 【PhotoShop绘制大眼睛的姑娘教程】
- When Linux Runs Out of Memory
- 实现验证码的java代码