卡特兰数问题

问题:给定N个节点,能构成多少种不同的二叉树.

回答:卡特兰数运用.

import java.util.*;
import java.math.*;
public class Main{
    public static void main(String[] args)
    {
        int n;
        Scanner in=new Scanner(System.in);
        BigInteger one=BigInteger.ONE;
        BigInteger four=new BigInteger("4");
        BigInteger two=new BigInteger("2");
        BigInteger st=null;
        BigInteger ans=null;
        while(in.hasNextInt())
        {
            n=in.nextInt();
            ans=BigInteger.ONE;
            for(int i=2;i<=n;i++)
            {
                st=new BigInteger(""+i);
                ans=ans.multiply(st.multiply(four).subtract(two)).divide(st.add(one));
            }
            System.out.println(ans);
        }
    }
}

原文地址:https://www.cnblogs.com/benchao/p/4548804.html