N个节点的不同的树的数目。这样

随便取一个节点作为根,那么他左边和右边的儿子节点个数就确定了,假定根节点标号为x,那么左子树的标号就从1到x-1,共x-1个,右子树的标号就从x+1到n,共n-x个,那么我们的x从1取到n,就获得了所有的情况数

这是一个递推的式子,初始值与卡特兰数的初值相同。所以,解正是卡特兰数。又由于节点有序,所以乘上N!。

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
import java.io.InputStreamReader; class Cont{
BigDecimal []num;
Cont(){
num=new BigDecimal[110];
num[0]=new BigDecimal(1);
BigDecimal Tmp;
for(int i=1;i<=100;i++){
Tmp=new BigDecimal(i);
num[i]=num[i-1].multiply(Tmp);
}
}
} public class Main{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
BigDecimal []Can=new BigDecimal[110];
Can[0]=new BigDecimal(1);
BigDecimal B,C,D;
Cont Conmul=new Cont();
for(int i=1;i<=100;i++){
B=new BigDecimal(4*i-2);
C=new BigDecimal(i+1);
D=Can[i-1].multiply(B);
Can[i]=D.divide(C);
}
while(in.hasNext()){
int x=in.nextInt();
if(x==0) break;
BigDecimal ans=new BigDecimal(1);
ans=ans.multiply(Can[x]);
ans=ans.multiply(Conmul.num[x]);
System.out.println(ans);
}
}
}

  

HDU 1131的更多相关文章

  1. hdu 1130,hdu 1131(卡特兰数,大数)

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. HDU 1131 Count the Trees 大数计算

    题目是说给出一个数字,然后以1到这个数为序号当做二叉树的结点,问总共有几种组成二叉树的方式.这个题就是用卡特兰数算出个数,然后因为有编号,不同的编号对应不同的方式,所以结果是卡特兰数乘这个数的阶乘种方 ...

  3. Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)

     Count the Trees  Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...

  4. HDU 1131 Count the Trees

    卡特兰数再乘上n的阶乘 #include<iostream> #include<cstdio> using namespace std; #define base 10000 ...

  5. hdu 1023 hdu 1131

    How Many Trees? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...

  6. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  7. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  8. Hdu 4311-Meeting point-1 曼哈顿距离,前缀和

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4311 Meeting point-1 Time Limit: 2000/1000 MS (Java/Oth ...

  9. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

随机推荐

  1. [IOS]mac以太网连接

    今天玩了一下苹果一体机.感觉还是蛮不错的,只是.就是用以太网连接的时候遇到了一点问题.用这篇文章记录一下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/ ...

  2. Android之应用开发基础

    Android应用开发基础 英文地址:http://developer.android.com/guide/components/fundamentals.html 本人英语水平不高,如有翻译不当请指 ...

  3. html5开发手机打电话发短信功能,html5的高级开发,html5开发大全,html手机电话短信功能具体解释

    在非常多的手机站点上,有打电话和发短信的功能,对于这些功能是怎样实现的呢.事实上不难,今天我们就用html5来实现他们. 简单的让你大开眼界.HTML5 非常easy写,但创建网页时,您常常须要反复做 ...

  4. Codeforces Round #272 (Div. 2) 题解

    Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...

  5. UVA 11728 - Alternate Task 数学

    Little Hasan loves to play number games with his friends. One day they were playing a game whereone ...

  6. Unable to access the IIS metabase

    https://stackoverflow.com/questions/12859891/error-unable-to-access-the-iis-metabase 解决方法1 On Window ...

  7. [AHOI 2009] 同类分布

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1799 [算法] 数位DP [代码] #include<bits/stdc++. ...

  8. 18. 4Sum[M]四数之和

    题目 Given an array nums of n integers and an integer target, are there elements a, b, c and d in nums ...

  9. Spark基本运行流程

    不多说,直接上干货! Spark基本运行流程 Application program的组成 Job : 包含多个Task 组成的并行计算,跟Spark action对应. Stage : Job 的调 ...

  10. c# CacheHelper缓存帮助类

    一.开篇 主要功能:改善程序性能.服务器的响应速度,尤其是当数据的处理过程变得复杂以及访问量变大时,变得比较明显.有些数据并非时刻在发生变化,如果我们可以将一些变化不频繁的数据的最终计算结果(包括页面 ...