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. TYVJ1939 玉蟾宫

    背景 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. 描述 这片土地被分成N*M个格子,每个格子里写着'R'或者'F',R代 ...

  2. jsp中 response和request区别

    1.response 属于重定向请求: 其地址栏的URL会改变: 会向服务器发送两次请求: 2. request 属于请求转发: 其地址栏的URL不会改变: 向服务器发送一次请求: 举一个区分它们的简 ...

  3. Oracle大数据常见优化查询

    [转]http://www.cnblogs.com/myhappylife/p/5006774.html 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的 ...

  4. PHP高效率写法(详解原因)

    1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...

  5. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划)

    题意: 求解最大递增子序列. 例如:3 1 3 2 输入 3  个数 1 3 2 则递增子序列有 {1} {3} {2} {1 3} {1 2} ,故输出子序列的最大和 4 解题思路: x[n](n个 ...

  6. [LeetCode] Word Ladder II

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  7. Mvc3提交表格验证(转载)

    Model层:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System ...

  8. 3月23.CSS表格布局

    360表格布局: CSS定义标签: @charset "utf-8";/* CSS Document */.bt1{ border:#309 solid 1px; height:1 ...

  9. XSS跨站脚本攻击实例讲解,新浪微博XSS漏洞过程分析

    2011年6月28日晚,新浪微博遭遇到XSS蠕虫攻击侵袭,在不到一个小时的时间,超过3万微博用户受到该XSS蠕虫的攻击.此事件给严重依赖社交网络的网友们敲响了警钟.在此之前,国内多家著名的SNS网站和 ...

  10. [Unity3D]关于Assets资源目录结构管理

    原地址:http://www.cnblogs.com/hisiqi/p/3203515.html 分享个我们项目常用的目录结构,微调过很多次,最终到了这个版本.个人认为这种管理资源方式是不错的.欢迎探 ...