hdu 1023 卡特兰数+高精度

Posted xjhz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 1023 卡特兰数+高精度相关的知识,希望对你有一定的参考价值。

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)


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
 百度百科卡特兰数;
java代码;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        BigInteger[] a=new BigInteger[110];
        a[0]=new BigInteger("1");
        for(int i=1;i<=100;i++)
        {
            int  h=4*i-2;
            int  d=i+1;
            String b="",c="";
            int[] k=new int[10];
            int flag=0;
            while(h!=0)
            {
                k[flag++]=h%10;
                h/=10;
            }
            for(int j=flag-1;j>=0;j--){
                b+=k[j];
            }
            a[i]=a[i-1].multiply(new BigInteger(b));
            flag=0;
            while(d!=0)
            {
                k[flag++]=d%10;
                d/=10;
            }
            for(int j=flag-1;j>=0;j--){
                c+=k[j];
            }
            a[i]=a[i].divide(new BigInteger(c));
        }
        int n;
        while(cin.hasNext())
        {
            n=cin.nextInt();
            System.out.println(a[n]);
        }
    }
}

 

以上是关于hdu 1023 卡特兰数+高精度的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1023 Traning Problem 大数卡特兰数

Train Problem II HDU 1023 卡特兰数

HDU 1023 Train Problem II 大数打表Catalan数

卡特兰数

用到了卡特兰数的性质,还有高精度压位,筛法找素数

Buy the Ticket(卡特兰数+递推高精度)