zoukankan      html  css  js  c++  java
  • 卡特兰数问题

    问题:给定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);
            }
        }
    }

  • 相关阅读:
    Spring boot 启动图片
    Spring Cloud 从入门到入门
    理解错误的 Arrays.asList()
    git github 对代码的管理
    【POJ 2154】Color
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    [数据结构]Hash Table(哈希表)
  • 原文地址:https://www.cnblogs.com/benchao/p/4548804.html
Copyright © 2011-2022 走看看