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个节点形成的二叉树的 ...
随机推荐
- php版本的discuzX3.2部署的问题收集
1.登陆后台老是自动退出是怎么回事? 解决方法:用ftp上線下載文件下在跟目錄/config/config_global.php把$_config['admincp']['checkip'] = 1 ...
- BZOJ2301 莫比乌斯反演
题意:a<=x<=b,c<=y<=d,求满足gcd(x,y)=k的数对(x,y)的数量 ((x,y)和(y,x)不算同一个) 比hdu1695多加了个下界,还有 ...
- poj 3311 tsp入门
题意:n+1个点:0--n,找一条路径从0点出发遍历1--n的点再回到0,每个点可经过不止一次,求最短路径 裸的TSP问题,先用Floyd求出各个点之间最短路,再状压dp即可 用n+1位二进制表示状态 ...
- 大数据测试之hadoop命令大全
1.列出所有Hadoop Shell支持的命令 $ bin/hadoop fs -help2.显示关于某个命令的详细信息 $ bin/hadoop fs -help command-name3.用户可 ...
- 过滤器在Web开发应用------解决中文乱码
src/com/Encoding.java package com; import java.io.IOException; import javax.servlet.Filter; import j ...
- ActionBar右边菜单按钮的添加
在res目录下新建文件夹menu,存放men.xml文件 menu.xml <menu xmlns:android="http://schemas.android.com/apk/re ...
- 清空file input框
测试环境:OS --> winXPBrowsers --> IE6+, FF 3.0.11, FF 3.5, Opera 9.64, Opera 10 beta 2, Safari 4, ...
- Visual Studio Online Integrations-Customer support
原文:http://www.visualstudio.com/zh-cn/explore/vso-integrations-directory-vs
- UISearchBar和 UISearchDisplayController的使用
感觉好多文章不是很全面,所以本文收集整合了网上的几篇文章,感觉有互相补充的效果. 如果想下载源码来看:http://code4app.com/search/searchbar .本源码与本文无关 1. ...
- php 开启curl,重启php-fpm服务
1,找到php.ini配置 find / -name 'php.ini' /usr/local/php/etc/php.ini 找到extension=php_curl.dll 把前面的分号去掉即可. ...