HDU How Many Trees?

原题链接:

思路:卡特兰数,建议百度一下,挺实用的一个组合数。还有一点这是一道大数题,为了偷懒,我拿出了我的java大数类

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

/**
 * Created by ZUOYANBIN1 on 2017/9/18.
 */
public class Main {
    static int n = 0;
    static void solve(){
        BigInteger ans = new BigInteger("1");
        for(int i = 1; i <= n; i++){
            ans = ans.multiply(new BigInteger(String.valueOf(4 * i - 2)))
                    .divide(new BigInteger(String.valueOf(i + 1)));
        }
        System.out.println(ans);
    }
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            n = in.nextInt();
            solve();
        }
    }
}

你可能感兴趣的:(HDU)