How Many Trees?

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

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 
http://blog.csdn.net/sunshine_yg/article/details/47685737
卡特兰数 #include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
const int base = ;
const int N = + ;
int katelan[N][N];
int main()
{
katelan[][] = ;
katelan[][] = ;
katelan[][] = ;
for (int i = ; i <= ; i++)
{
for (int j =; j<; j++)//大数乘法
{
katelan[i][j] += katelan[i - ][j] * ( * i - );
katelan[i][j + ] += katelan[i][j] / base;
katelan[i][j] %= base;
}
int temp;
for (int j = ; j > ; j--)//大数除法
{
temp=katelan[i][j] % (i + );
katelan[i][j-]+=temp* base;
katelan[i][j] /= (i + );
}
}
int n;
while (cin >> n)
{
int i = ;
while (katelan[n][i] == )i--;
cout << katelan[n][i--];
while (i > )
printf("%04d", katelan[n][i--]);
cout << endl;
}
return ;
}

HDU1130 卡特兰数的更多相关文章

  1. hdu-1130(卡特兰数+大数乘法,除法模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130 卡特兰数:https://blog.csdn.net/qq_33266889/article/d ...

  2. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  3. 卡特兰数(Catalan)

    卡特兰数又称卡塔兰数,英文名Catalan number,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名,其前几项为 : 1, 2, ...

  4. NOIP2003pj栈[卡特兰数]

    题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重要性不言自明,任何 ...

  5. 卡特兰数 (Catalan)

    卡特兰数:(是一个在计数问题中出现的数列) 一般项公式: 1.         或       2.   递归公式: 1.  或 2. 注:全部可推导. (性质:Cn为奇数时,必然出现在奇数项 2k- ...

  6. HDU 5673 Robot ——(卡特兰数)

    先推荐一个关于卡特兰数的博客:http://blog.csdn.net/hackbuteer1/article/details/7450250. 卡特兰数一个应用就是,卡特兰数的第n项表示,现在进栈和 ...

  7. HDU 1023 Traning Problem (2) 高精度卡特兰数

    Train Problem II Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Sub ...

  8. LightOJ1170 - Counting Perfect BST(卡特兰数)

    题目大概就是求一个n个不同的数能构造出几种形态的二叉排序树. 和另一道经典题目n个结点二叉树不同形态的数量一个递推解法,其实这两个问题的解都是是卡特兰数. dp[n]表示用n个数的方案数 转移就枚举第 ...

  9. UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)

    题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...

随机推荐

  1. 【bzoj1016】 JSOI2008—最小生成树计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1016 (题目链接) 题意 求图的最小生成树计数. Solution %了下题解,发现要写矩阵树,15 ...

  2. HOPE——懦怯囚禁人的灵魂,希望可以感受自由。强者自救,圣者渡人。

    人世间最美好的,就是希望 人世间最美好的,就是友谊 祝福所有相信希望的人,因为每个充满希望的人,都如此美丽. <肖申克的救赎>中的经典台词 1.Hope is a good thing,  ...

  3. Android系统中的广播(Broadcast)机制简要介绍和学习计划

    在Android系统中,广播(Broadcast)是在组件之间传播数据(Intent)的一种机制:这些组件甚至是可以位于不同的进程中,这样它就像Binder机制一样,起到进程间通信的作用:本文通过一个 ...

  4. groovy-脚本和类

    在groovy中定义类和java中是一样的.类的方法可以是static,也可以是非static的. groovy中的方法可以是public, protected, private,同时也支持java中 ...

  5. js中对象概念的声明

  6. js校验表单后提交表单的三种方法总结

    第一种: 复制代码 代码如下: <script type="text/javascript">         function check(form) { if(fo ...

  7. event.keycode值大全

    window.event.keycode-获取按下的键盘值   event.keycode值大全1 keycode 8 = BackSpace BackSpace 2 keycode 9 = Tab ...

  8. 如何获取xcassets中LaunchImage图片

    NSDictionary * dic = @{@"320x480" : @"LaunchImage-700", @"320x568" : @ ...

  9. 漂亮的title提示信息

    <HTML> <HEAD> <title>一种很酷的文字提示效果演示</title> <style> .tableBorder7{width ...

  10. 混合应用中的javascript实践

    混合应用中的javascript实践 混合应用(hybird app) 在几年前便进入大众视野,近来更是越发风生水起,深受人民群众的喜爱. 目录 概念 什么是混合应用 混合方式 交互 方法注入 参数传 ...