HDU-1023 Train Problem II 出栈序列问题

    题目:HDU-1023

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1023

    题目:

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7427    Accepted Submission(s): 4008


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.
 
    先上代码,用的是Java大数据:

import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    BigInteger a=new BigInteger("1");
    BigInteger b=new BigInteger("2");
    BigInteger c=new BigInteger("4");
    BigInteger d=new BigInteger("1");
    BigInteger ans[]=new BigInteger[105];
    ans[1]=a;
    for(int i=2;i<=100;i++){
        d=d.add(a);
        ans[i]=ans[i-1].multiply(c.multiply(d).subtract(b)).divide(d.add(a));
    }
    while(input.hasNext()){
    int t=input.nextInt();
    System.out.println(ans[t]);
    }
    }
}

    嗯哼,经过本人 并不是很严密的推论,记住,很(不)严密,看看就行了。

    当入栈元素只有1个的时候,毫无疑问出栈序列只有一种。

    当入栈元素为2个的时候,比如1,2,出栈序列就有1,2和2,1两种,如果这个不理解的话回头看看栈的定义吧。

    当入栈元素为3个的时候,1,2,3,则分别有1开头,2开头,3开头的序列,分别是,1*f(n-1)+f(n-1)*1,然后还剩下中间以2开头的,然后就可以转化为定义式来看待序列总数。

    大概就是这样,具体的也搞不太懂,以后再深入研究吧。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值