zoukankan      html  css  js  c++  java
  • 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): 7918    Accepted Submission(s): 4241


    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
     
    出栈问题。卡特兰数。
    用java解决大数是多么的方便啊!!!
    第一个java程序。
     
    import java.util.*;
    import java.math.BigInteger;
    
    public class Main {
    
        public static void main(String[] args) {
            BigInteger[] a=new BigInteger[105];
            a[0]=BigInteger.valueOf(1);
            a[1]=BigInteger.valueOf(1);
            for(int i=2;i<=100;i++)
                a[i]=BigInteger.valueOf(0);
            for(int i=2;i<=100;i++)
                for(int j=1;j<=i;j++)
                    a[i]=a[i].add(a[j-1].multiply(a[i-j]));
            //System.out.println(a[10]);
            Scanner in =new Scanner(System.in);
            int n;
            while(in.hasNext())
            {
                n=in.nextInt();
                System.out.println(a[n]);
            }
        }
    
    }
    j
    View Code
  • 相关阅读:
    Java:抽象类与接口
    OOP编程思想:类的设计原则
    Win10系统下设置Go环境变量和go语言开启go module
    Windows下Golang安装Iris框架
    AOS.JS 和基于Animation.css的收费库WOW.JS相似
    文本比价工具
    MySQL Order By Rand()效率
    datatable分页
    PHP面向对象之魔术方法
    PHP面向对象之序列化与反序列化
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5531897.html
Copyright © 2011-2022 走看看