hdoj.1023 Train Problem II【卡特兰数列】 2015/08/27
2015-08-27 10:08
375 查看
Train Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6927 Accepted Submission(s): 3749
[align=left]Problem Description[/align]
As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.
[align=left]Input[/align]
The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.
[align=left]Output[/align]
For each test case, you should output how many ways that all the trains can get out of the railway.
[align=left]Sample Input[/align]
1 2 3 10
[align=left]Sample Output[/align]
1 2 5 16796 Hint The result will be very large, so you may not process it by 32-bit integers.
[align=left]Author[/align]
Ignatius.L
注:卡特兰数列模板题
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int c[101][100],b[100]; void catalan(){ memset(c,0,sizeof(c)); c[1][0]=1;b[1]=1; int i,j,k,len=1,flag; for( i=2;i<=100;++i ){ k = 4 * i - 2; flag = 0; for( j = 0 ; j < len ; ++j ) //乘 c[i][j] = c[i-1][j] * k; for( j = 0 ; j < len ; ++j ){ // 进位 k = c[i][j] + flag; c[i][j] = k % 10; flag = k / 10; } while( flag ){ //进位 c[i][len++] = flag%10; flag /= 10; } flag = 0; for( j=len-1;j>=0;--j ){ // 除 k = flag * 10 + c[i][j]; c[i][j] = k / (i+1); flag = k % (i+1); } while( !c[i][len-1] ) //高位除零 len--; b[i] = len; // 记录当前项的位数 } } int main(){ int n,i,ans=1; catalan(); while( ~scanf("%d",&n) ){ for( i = b -1 ; i >= 0 ; --i ) printf("%d",c [i]); printf("\n"); } return 0; }
相关文章推荐
- 2015.6.17(Tair)
- oc assign / copy / retain / 容器 / 多态
- oc MRC内存管理机制alloc/retain/copy/release/autorelease
- Syntax error, type annotations are available only when source level is at least 1.8
- install ftp client on kail
- Container With Most Water
- LightOJ 1403 - Air Raid【二分匹配】
- Leetcode: Contains Duplicate
- Leetcode: Factorial Trailing Zeroes
- ideaiu的使用
- CCComponentContainer,CCComponent解析
- 安装APK:Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
- 异常:org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1) B. Minimization 贪心 dp
- LeetCode题解:Factorial Trailing Zeroes
- HDU2473 - Junk-Mail Filter 利用虚拟数组实现删除并查集的节点
- 【图论】【最小生成树】[IOI2003]maintain
- [捉虫记录]关于Cascade Training Error的bug
- failure during conversion to COFF: file invalid or corrupt
- 【HDOJ 1021】 Fibonacci Again (矩阵快速幂(裸))