HDU1134 Game of Connections
来源:互联网 发布:手机淘宝所在地怎么改 编辑:程序博客网 时间:2024/05/18 02:41
Game of Connections
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4430 Accepted Submission(s): 2574
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
另附上卡特兰数的公式:
h(n)=h(n-1)*(4*n-2)/(n+1)(n>=1)
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int a[102][102];void multiply(int d,int k);void divide(int d,int k);int main(){ int n; memset(a[1],0,sizeof(a[1])); a[1][99] = 1; for(int i = 2;i <= 100;i++){ multiply(i-1,4*i-2); divide(i,i+1); } while(~scanf("%d",&n)&&n!=-1){ int i; for(i = 0;i < 100&&!a[n][i];i++); for(int j = i;j < 100;j++) printf("%d",a[n][j]); printf("\n"); } return 0;}void multiply(int d,int k){ int temp,add = 0; for(int i = 99;i >= 0;i--){ temp = a[d][i]*k+add; a[d+1][i] = temp%10; add = temp/10; } return;}void divide(int d,int k){ int temp=0; for(int i = 0;i < 100;i++){ temp = temp*10+a[d][i]; a[d][i] = temp/k; temp = temp%k; } return;}
0 0
- hdu1134-Game of Connections
- HDU1134 Game of Connections
- HDU1134 Game of Connections 高精度+DP
- hdu1134 Game of Connections 卡特兰数(大数)
- hdu1134 Game of Connections(卡特兰数)
- hdu1134 Game of Connections(Catalan+高精)
- HDU1134 Game of Connections(大数乘法+打表)
- hdu1134 Game of Connections(Catalan数, 顺便附上大数类模板)
- HDU1134——Game of Connections (大数乘法,除法)+ (卡特兰数列)
- 1134 ---( Game of Connections )
- poj2084 Game of Connections
- Game of Connections
- acm-Game of Connections
- Game of Connections
- poj2084 Game of Connections
- Game of Connections
- WOJ1268-Game of Connections
- Game of Connections HDU
- Spring框架学习(10):基于注解的方式配置Bean
- linux初学 unit13
- CSS实现三角形的方法之一--利用 border 属性实现三角形
- 大数据处理思路与mysql分区1
- 学生信息管理系统
- HDU1134 Game of Connections
- 第九单元练习题
- 函数linspace生成按等差形式排列的行向量
- java面向对象第6章 异常1
- R语言数据可视化:ggplot2中的qplot()函数
- 关闭回显
- 多线程中的单例模式
- Fabric架构解析
- Problem G: 字符串类(II)