HDU——1023 Train Problem II
2024-08-31 00:06:55
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
2
3
10
Sample Output
1
2
5
16796
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=;a[][]=b[]=; ;i<;i++) { ;j<len;j++) a[i][j]=a[i-][j]*(*i-); sum=; ;j<len;j++) { tmp=sum+a[i][j]; a[i][j]=tmp%; sum=tmp/; } while(sum) { a[i][len++]=sum%; sum/=; } ;j>=;j--) { tmp=sum*+a[i][j]; a[i][j]=tmp/(i+); sum=tmp%(i+); } ]) len--; b[i]=len; } } int main() { catelan(); while(~scanf("%d",&n)) { ;i>=;i--) printf("%d",a[n][i]); printf("\n"); } }
最新文章
- 终于等到你:CYQ.Data V5系列 (ORM数据层)最新版本开源了
- CentOS7下安装Python的pip
- SDAutoLayout:比masonry更简单易用的自动布局库
- 【转】内部Handler类引起内存泄露
- iOS5中UIViewController的新方法
- Linux 硬盘分区
- WAS集群服务的关闭与启动
- Java_SSH项目主要步骤记录
- C#语言和SQL Server第十章笔记
- [bzoj1910] [Ctsc2002] Award 颁奖典礼
- Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths
- BZOJ5206 JSOI2017原力(三元环计数)
- Spark2.2+ES6.4.2(三十一):Spark下生成测试数据,并在Spark环境下使用BulkProcessor将测试数据入库到ES
- C#获取文件MD5值方法
- day29(对象转xml(使用java))
- iterm2用法与技巧
- Java:集合,Map接口框架图
- 耗时 2 年,用 8.5 万块乐高积木最牛复刻 Apple Park
- thinkPHP中phpexcel的导出功能
- Yii命令行模式