hdoj 1134 Game of Connections 【catalan数列】
来源:互联网 发布:linux 中断 工作队列 编辑:程序博客网 时间:2024/04/29 04:55
Game of Connections
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3468 Accepted Submission(s): 1975
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
catalan数列,公式a [ n ] = a[ n - 1 ] * ( 4 * n - 2) / ( n + 1 ):
#include<stdio.h>#include<string.h>int a[101][500];int b[101];//存储位数void catalan(){ int i,j; int len; int carry,temp; a[1][0]=b[1]=len=1; for(i=2;i<=100;i++) { for(j=0;j<len;j++) { a[i][j]=a[i-1][j]*(4*i-2); } carry=0; for(j=0;j<len;j++) { temp=carry+a[i][j]; a[i][j]=temp%10; carry=temp/10; } while(carry)//进位 { a[i][len++]=carry%10; carry/=10; } carry=0; for(j=len-1;j>=0;j--) { temp=a[i][j]+carry*10; a[i][j]=temp/(i+1); carry=temp%(i+1); } while(!a[i][len-1])//去掉高位零 len--; b[i]=len; }}int main(){ int n,i; catalan(); while(scanf("%d",&n)!=EOF) { if(n==-1) break; for(i=b[n]-1;i>=0;i--) printf("%d",a[n][i]); printf("\n"); } return 0;}
0 0
- hdoj 1134 Game of Connections 【catalan数列】
- hdu 1134 game of connections(Catalan Number)
- [Catalan] HDU 1134 Game of Connections
- hdu 1134 Game of Connections (Catalan数)
- HDOJ 1134: Game of Connections
- hdu 1134 Game of Connections(卡特兰(Catalan)公式)
- hdu 题目1134 Game of Connections (卡塔兰数 catalan number)
- [ACM] hdu 1134 Game of Connections(大数+Catalan数)
- HDU 1134 Game of Connections(Catalan + 大数)
- hdoj 1134 Game of Connections【水】【java】
- hdu/hdoj 1134 Game of Connections
- HDOJ HDU 1134 Game of Connections
- POJ2084 Game of Connections(catalan数)
- 2.3.7--Game of Connections--标准catalan
- poj2084 Game of Connections(Catalan)
- 1134 ---( Game of Connections )
- hdoj 1134 Game of Connections(卡特兰数&&大数)
- hdoj-1134-Game of Connections【卡特兰数】
- 排序算法之归并排序
- Android 网络框架学习之OKHttp
- Java反射生成json和解析json
- java变量初始化
- css去掉iPhone、iPad默认按钮样式
- hdoj 1134 Game of Connections 【catalan数列】
- hdu 4870 Rating (高斯消元解概率dp)
- Exception
- [web安全]SQL注入防御方法总结
- 驱动第一天(韦东山视频) 学习笔记
- csdn 最小向量乘积
- java的数据类型——基本类型、引用类型
- Android Json处理之Gson
- 黑马程序员——java基础学习---泛型、Map集合及扩展、高级for循环