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();
    }

}

你可能感兴趣的:(hdu 1131 Count the Trees 卡特兰数+java)