hdu 1131 Count the Trees 卡特兰数+java

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        int i=0,n=0;
        BigInteger[] a=new BigInteger[150];
        a[0]=BigInteger.ONE;
        for(i=1;i<=105;i++)
            a[i]=a[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
        while(in.hasNextInt())
        {
            n=in.nextInt();
            if(n==0) break;
            BigInteger ans=BigInteger.ONE;
            for(i=1;i<=n;i++)
                ans=ans.multiply(BigInteger.valueOf(i));
            ans=ans.multiply(a[n]);
            System.out.println(ans);
        }
        in.close();
    }

}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

原文地址:https://www.cnblogs.com/xryz/p/4847775.html