HDU——1023 Train Problem II
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU——1023 Train Problem II相关的知识,希望对你有一定的参考价值。
Train Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9701 Accepted Submission(s): 5210
Problem Description
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.
Input
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.
Output
For each test case, you should output how many ways that all the trains can get out of the railway.
Sample Input
1
2
3
10
Sample Output
1
2
5
16796
Hint
The result will be very large, so you may not process it by 32-bit integers.
Author
Ignatius.L
Recommend
题意:给你n辆火车,编号从1到n,问你有多少种出站的可能序列。
思路:火车进出站问题,首先考虑卡特兰数(不要忘了高精哦)
代码:
#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define N 110 using namespace std; int n,len,sum,tmp,a[N][N],b[N]; int catelan() { len=1;a[1][0]=b[1]=1; for(int i=2;i<110;i++) { for(int j=0;j<len;j++) a[i][j]=a[i-1][j]*(4*i-2); sum=0; for(int j=0;j<len;j++) { tmp=sum+a[i][j]; a[i][j]=tmp%10; sum=tmp/10; } while(sum) { a[i][len++]=sum%10; sum/=10; } for(int j=len-1;j>=0;j--) { tmp=sum*10+a[i][j]; a[i][j]=tmp/(i+1); sum=tmp%(i+1); } while(!a[i][len-1]) len--; b[i]=len; } } int main() { catelan(); while(~scanf("%d",&n)) { for(int i=b[n]-1;i>=0;i--) printf("%d",a[n][i]); printf("\n"); } }
以上是关于HDU——1023 Train Problem II的主要内容,如果未能解决你的问题,请参考以下文章
C - Train Problem II——(HDU 1023 Catalan 数)
Train Problem II HDU 1023 卡特兰数
HDU1023 Train Problem IICatalan数
(母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023