Game of Connections(标准卡特兰数及高精度)
来源:互联网 发布:php远程ftp上传图片 编辑:程序博客网 时间:2024/06/05 06:22
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
Source
Asia 2004, Shanghai (Mainland China), Preliminary
Recommend
Eddy
h(n)=h(n-1)*(4*n-2)/(n+1);
代码:
#include<iostream> #include<cstdio> using namespace std; int a[101][101]; int b[101]; void catalan() { int i,j,x,len; a[1][0]=b[1]=len=1; for(i=2;i<101;i++) { for(j=0,x=0;j<len;j++) //乘法 { a[i][j]=a[i-1][j]*(4*i-2)+x; //处理相乘的结果 x=a[i][j]/10; a[i][j]%=10; } while(x>0) //进位 { a[i][len++]=x%10; x/=10; } for(j=len-1,x=0;j>=0;j--) //除法 { a[i][j]=a[i][j]+10*x; x=a[i][j]%(i+1); a[i][j]/=(i+1); } while(a[i][len-1]==0&&len>0) len--; b[i]=len; } } int main() { int n; while(scanf("%d",&n)!=EOF&&n!=-1) { catalan(); for(int i=b[n]-1;i>=0;i--) { printf("%d",a[n][i]); } printf("\n"); } return 0; }
阅读全文
0 0
- Game of Connections(标准卡特兰数及高精度)
- Poj 2084 Game of Connections(高精度卡特兰数)
- HDU 1134 Game of Connections (高精度卡特兰数)
- Game of Connections(卡特兰数)
- HDU 1134 Game of Connections 高精度卡特兰数
- POJ Game of Connections 卡特兰数
- Game of Connections 卡特兰数
- hdu 1134 Game of Connections(卡特兰数)
- POJ 2084 Game of Connections(卡特兰数,JAVA)
- hdu1134 Game of Connections(卡特兰数)
- poj 2084 Game of Connections (卡特兰数、大数)
- hdu1134 Game of Connections 卡特兰数(大数)
- POJ 2084 Game of Connections 卡特兰数
- 卡特兰数:poj 2084 Game of Connections+hdu 1023
- hdu 1134 Game of Connections 【卡特兰数+大数】
- hdu 1134 Game of Connections(卡特兰数模板题)
- hdoj 1134 Game of Connections(卡特兰数&&大数)
- hdoj-1134-Game of Connections【卡特兰数】
- zec挖矿(zcash挖矿)鱼池跟蚂蚁矿池的比较到底哪个好?哪个收益高?
- Tree(3)--二叉树的实现及四种遍历(递归/非递归)
- c++11使用可变参数实现日志打印
- 图的创建,遍历
- WEBRTC 发送端拥塞控制
- Game of Connections(标准卡特兰数及高精度)
- XShell 显示中文
- SQL经典语句用法整合
- Java的BigDecimal类
- 【实践】cephfs + Ganesha环境部署
- java后台封装json数据学习(一)
- 数据级的权限管理和功能级的权限管理的区别,不使用框架(shiro,springsecurity)做权限设计的思考
- 正、反向代理区别
- ubuntu16.04配置VSCode编译执行cpp