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
We have carefully selected several similar problems for you:  1133 1022 1131 1134 2067 
 
题意:给你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");
    }
}

最新文章

  1. 终于等到你:CYQ.Data V5系列 (ORM数据层)最新版本开源了
  2. CentOS7下安装Python的pip
  3. SDAutoLayout:比masonry更简单易用的自动布局库
  4. 【转】内部Handler类引起内存泄露
  5. iOS5中UIViewController的新方法
  6. Linux 硬盘分区
  7. WAS集群服务的关闭与启动
  8. Java_SSH项目主要步骤记录
  9. C#语言和SQL Server第十章笔记
  10. [bzoj1910] [Ctsc2002] Award 颁奖典礼
  11. Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths
  12. BZOJ5206 JSOI2017原力(三元环计数)
  13. Spark2.2+ES6.4.2(三十一):Spark下生成测试数据,并在Spark环境下使用BulkProcessor将测试数据入库到ES
  14. C#获取文件MD5值方法
  15. day29(对象转xml(使用java))
  16. iterm2用法与技巧
  17. Java:集合,Map接口框架图
  18. 耗时 2 年,用 8.5 万块乐高积木最牛复刻 Apple Park
  19. thinkPHP中phpexcel的导出功能
  20. Yii命令行模式

热门文章

  1. jQuery——表单应用(3)
  2. Lightoj 1020 - A Childhood Game (博弈)
  3. linux学习之路5 系统常用命令
  4. 离散化+BFS HDOJ 4444 Walk
  5. 300 Longest Increasing Subsequence 最长上升子序列
  6. Java泛型Object和?区别
  7. 日期时间选择器插件flatpickr
  8. Spring.Net学习笔记(八)-设置配置文件参数
  9. lua_protobuf
  10. ci框架中model简单的mysql操作