HDU1130 卡特兰数
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
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?
line representing the number of elements of the set.
with the answer to the previous question.
2
3
2
5
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 卡特兰数的更多相关文章
- hdu-1130(卡特兰数+大数乘法,除法模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130 卡特兰数:https://blog.csdn.net/qq_33266889/article/d ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- 卡特兰数(Catalan)
卡特兰数又称卡塔兰数,英文名Catalan number,是组合数学中一个常出现在各种计数问题中出现的数列.由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名,其前几项为 : 1, 2, ...
- NOIP2003pj栈[卡特兰数]
题目背景 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重要性不言自明,任何 ...
- 卡特兰数 (Catalan)
卡特兰数:(是一个在计数问题中出现的数列) 一般项公式: 1. 或 2. 递归公式: 1. 或 2. 注:全部可推导. (性质:Cn为奇数时,必然出现在奇数项 2k- ...
- HDU 5673 Robot ——(卡特兰数)
先推荐一个关于卡特兰数的博客:http://blog.csdn.net/hackbuteer1/article/details/7450250. 卡特兰数一个应用就是,卡特兰数的第n项表示,现在进栈和 ...
- HDU 1023 Traning Problem (2) 高精度卡特兰数
Train Problem II Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Sub ...
- LightOJ1170 - Counting Perfect BST(卡特兰数)
题目大概就是求一个n个不同的数能构造出几种形态的二叉排序树. 和另一道经典题目n个结点二叉树不同形态的数量一个递推解法,其实这两个问题的解都是是卡特兰数. dp[n]表示用n个数的方案数 转移就枚举第 ...
- UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)
题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...
随机推荐
- poj 1442 名次树
这回要求的是第k小的元素, 参考了ljl大神的模板,orz //insert 插入 //remove 删除 //_find 查找 //kth 返回root为根的树中第k小的元素 //treap插入.删 ...
- Android学习笔记02-Mac下编译java代码
在Mac OS上配置JDK 1.7. 一 下载 Mac版本的JDK1.7 从以下下载地址,下载Mac版本的JDk1.7 安装文件 jdk-7u79-macosx-x64.dmg. http://www ...
- java对象存储管理
java程序在内存中的存储分配情况: 堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令) 2.jvm只有一个堆区(heap)被所有线程共享, ...
- 详细解读Jquery各Ajax函数:$.get(),$.post(),$.ajax(),$.getJSON()
一,$.get(url,[data],[callback]) 说明:url为请求地址,data为请求数据的列表(是可选的,也可以将要传的参数写在url里面),callback为请求成功后的回调函数,该 ...
- PHP高效率写法(详解原因)
1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...
- 自定义NSLog无时间
#define SXLog(FORMAT, ...) fprintf(stderr,"file --\t%s\nline --\t%d\nmethd --\t%s\noutput --\t\ ...
- 锋利的jQuery-2--判断jQuery获取到的对象是否存在$().length
1.使用js获取不存在的对象: document.getElementById("tt").style.color = "red"; 如果网页中不存在id = ...
- c/s架构nginx+php-fpm通信原理
FastCGI是一个运用于Http Server和动态脚本语言间通信的接口,多数流行的Http Server都支持FastCGI,包括Apache.Nginx和lighttpd等.同时,Fas ...
- 获取JDBC中的ResultSet的记录的条数
方法一:利用ResultSet的getRow方法来获得ResultSet的总行数 Java代码 ResultSet rs; rs.last(); //移到最后一行 int rowCount = rs. ...
- 三大框架ssh
一.hibernate a.实体类+映射 b.lib hibernate包+oracle包(oracle安装里找) 映射:从类入手class+属性 a.映射的头文件在:hibernate3.jar- ...