How Many Trees?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3952    Accepted Submission(s): 2238

Problem Description
A binary search tree is a binary tree with root k such that any node v reachable from its left has label (v) <label (k) and any node w reachable from its right has label (w) > label (k). It is a search structure which can find a node with label x in O(n log n) average time, where n is the size of the tree (number of vertices).

Given a number n, can you tell how many different binary search trees may be constructed with a set of numbers of size n such that each element of the set will be associated to the label of exactly one node in a binary search tree?

 
Input
The input will contain a number 1 <= i <= 100 per line representing the number of elements of the set.
 
Output
You have to print a line in the output for each entry with the answer to the previous question.
 
Sample Input
1
2
3
 
Sample Output
1
2
5
 
Source
 
Recommend
Eddy   |   We have carefully selected several similar problems for you:  1131 1134 1133 1023 2067 
 

Statistic | Submit | Discuss | Note

Home | Top Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2017 HDU ACM Team. All Rights Reserved.
Designer & DeveloperWang Rongtao LinLe GaoJie GanLu
Total 0.015600(s) query 5, Server time : 2017-08-10 07:32:01, Gzip enabled
Administration

题目大意:

给定一个数n,你能说出有多少个不同的二进制搜索树可以用一组n个大小的数字来构造,这样集合的每个元素都将与二进制搜索树中的一个节点的标签相关联?

思路:

看题意,准是有很多大佬已经想到这个题就是让求一个二叉树有几种形态,那不就是一个裸的卡特兰数吗?!

然后我就信心满满的写了个卡特兰数,结果交上去接着就wa了。。。。

靠,卡特兰数到52就暴long long了!!!

唉,要用高精啊。。。。

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;
int n,len,ans,sum,tmp,a[N][N],b[N];
int catelan()
{
    len=; a[][]=b[]=;
    ;i<;i++)
    {
        ;j<len;j++)
         a[i][j]=a[i-][j]*(*i-);
        sum=;
        ;j<len;j++)
        {
            tmp=sum+a[i][j];
            a[i][j]=tmp%;
            sum=tmp/;
        }
        while(sum)
        {
            a[i][len++]=sum%;
            sum/=;
        }
        ;j>=;j--)
        {
            tmp=sum*+a[i][j];
            a[i][j]=tmp/(i+);
            sum=tmp%(i+);
        }
        ])
         len--;
        b[i]=len;
    }
}
int main()
{
    catelan();
    while(~scanf("%d",&n))
    {
        ;i>=;i--)
         printf("%d",a[n][i]);
        printf("\n");
    }
    ;
}

HDU——1130 How Many Trees?的更多相关文章

  1. hdu 1130 How Many Trees?(Catalan数)

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

  2. HDU 1130 How Many Trees?

    裸的卡特兰数 C++#include<iostream> #include<cstdio> using namespace std; #define base 10000 #d ...

  3. hdu 1130 How Many Trees? 【卡特兰数】

    题目 题意:给你一个数字n,问你将1~n这n个数字,可以组成多少棵不同的二叉搜索树. 1,2,5,14--根据输出中的规律可以看出这是一个卡特兰数的序列.于是代用卡特兰数中的一个递推式: 因为输入可取 ...

  4. HDU ACM 1134 Game of Connections / 1130 How Many Trees?(卡特兰数)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=1134 [解题背景]这题不会做,自己推公式推了一段时间,将n=3和n=4的情况列出来了,只发现第n项与 ...

  5. hdu 1693 Eat the Trees——插头DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...

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

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

  7. HDU 1392 Surround the Trees(凸包入门)

    Surround the Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. HDU - 1392 Surround the Trees (凸包)

    Surround the Trees:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意: 在给定点中找到凸包,计算这个凸包的周长. 思路: 这道题找出 ...

  9. HDU 1392 Surround the Trees (凸包周长)

    题目链接:HDU 1392 Problem Description There are a lot of trees in an area. A peasant wants to buy a rope ...

随机推荐

  1. httpd 安装ssl证书

    1) 安装ssl模块 # yum install mod_ssl -y Ps:安装完成后,会在/etc/httpd/conf.d/下生成一个ssl.conf配置文件. 2) 先建一个目录用来放ssl证 ...

  2. 窗体基础WINFORM

    winform 1.窗体: 造窗体界面: 窗体设计界面: 窗体类名不能重复! 属性: acceptbutton:回车是默认点击按钮 cancelbutton:按esc按键式默认的按钮 backcolo ...

  3. WebApi实现IHttpControllerSelector问题

    一.让Web API路由配置也支持命名空间参数/// <summary>    /// controller     /// 选择器    /// </summary>    ...

  4. cocos2dx在windows下搭建环境android报错

    报错:Program bash is not found in PATH   (如果按照我的方法来的话是没有这个错误的,我之前用别的方法的时候有但是后来还是没解决,写出来放到这里做参考吧) 参考原文: ...

  5. Android OKHttp网络框架

    好久没逛简书了.这周公司的项目也已经愉快的迭代了新版本,对于之前一直存留的东西一直没怎么梳理,今天想说说这两年特别火的网络框架.okhttp我想大部分Android开发者都不陌生,因为它的到来.是我们 ...

  6. plc学习笔记

    防抖编程代码备份 如果定时到了还未检测到下降沿,则认为信号有效.这一端程序主要是针对现场装料杯在输送过程中由于传送带原因,电眼时常产生无效停机信号,需要过滤,因此需要在电眼检测中添加防抖功能 2018 ...

  7. 读《实战GUI自动化测试》之:第三步,如何提高测试结果分析的效率

    转自:http://www.ibm.com/developerworks/cn/rational/r-cn-guiautotesting3/ 所谓自动化测试,就是“自动化”+“测试”.自动化本身显然不 ...

  8. Expectation-Maximization(EM) 算法

    Expectation-Maximization 算法是统计学中用来给带隐含变量的模型做最大似然(和最大后验概率)的一种方法.EM 的应用特别广泛,经典的比如做概率密度估计用的 Gaussian Mi ...

  9. 创建一个 Vue 的实例

    每个 Vue 应用都是通过 Vue 函数创建一个新的 Vue 实例开始的: var vm = new Vue({         // 选项 }) 选项:el.data.methods el: 类型: ...

  10. Commons_IO_FileUtils的使用

    commos_io.jar包下载地址:http://commons.apache.org/proper/commons-io/download_io.cgi 官方文档地址:http://commons ...