hdu 1130,hdu 1131(卡特兰数,大数)
How Many Trees?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3382 Accepted Submission(s): 1960
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?
2
3
import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
BigInteger [] h = new BigInteger[101];
h[1] = new BigInteger("1");
for(int i=2;i<=100;i++){
h[i] = h[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
}
Scanner sc =new Scanner (System.in);
while(sc.hasNext()){
int n =sc.nextInt();
System.out.println(h[n]);
}
}
}
hdu:1131 由n个带编号的结点组成二叉树的个数
思路:卡特兰数乘上编号的全排列
import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
BigInteger [] h = new BigInteger[101];
h[1] = new BigInteger("1");
for(int i=2;i<=100;i++){
h[i] = h[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
}
Scanner sc =new Scanner (System.in);
while(sc.hasNext()){
int n =sc.nextInt();
if(n==0)break;
System.out.println(h[n].multiply(fac(n)));
}
} private static BigInteger fac(int n) {
BigInteger sum = BigInteger.valueOf(1);
for(int i=1;i<=n;i++) sum=sum.multiply(BigInteger.valueOf(i));
return sum;
} }
hdu 1130,hdu 1131(卡特兰数,大数)的更多相关文章
- hdu 1130How Many Trees?(卡特兰数)
卡特兰数又称卡塔兰数,英文名Catalan number,是组合数学中一个常出现在各种计数问题中出现的数列. 以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)的名字来命名,其前几项为(从第零 ...
- HDU 1134 Game of Connections(卡特兰数+大数模板)
题目代号:HDU 1134 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1134 Game of Connections Time Limit: 20 ...
- 2014年百度之星程序设计大赛 - 初赛(第一轮) hdu Grids (卡特兰数 大数除法取余 扩展gcd)
题目链接 分析:打表以后就能发现时卡特兰数, 但是有除法取余. f[i] = f[i-1]*(4*i - 2)/(i+1); 看了一下网上的题解,照着题解写了下面的代码,不过还是不明白,为什么用扩展g ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- HDU 5673 Robot【卡特兰数】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 题意: 有一个机器人位于坐标原点上.每秒钟机器人都可以向右移到一个单位距离,或者在原地不动.如 ...
- HDU 5673 Robot ——(卡特兰数)
先推荐一个关于卡特兰数的博客:http://blog.csdn.net/hackbuteer1/article/details/7450250. 卡特兰数一个应用就是,卡特兰数的第n项表示,现在进栈和 ...
- HDU 4828 Grids(卡特兰数+乘法逆元)
首先我按着我的理解说一下它为什么是卡特兰数,首先卡特兰数有一个很典型的应用就是求1~N个自然数出栈情况的种类数.而这里正好就对应了这种情况.我们要满足题目中给的条件,数字应该是从小到大放置的,1肯定在 ...
- hdu-1130(卡特兰数+大数乘法,除法模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130 卡特兰数:https://blog.csdn.net/qq_33266889/article/d ...
- 【hdoj_1133】Buy the Ticket(卡特兰数+大数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目的意思是,m个人只有50元钱,n个人只有100元整钱,票价50元/人.现在售票厅没钱,只有50元 ...
随机推荐
- 基于jquery的扩展写法
(function($){ $.fn.aa = function(canshu){ html = $(this).text(); alert(html) }})(jQuery); (function( ...
- BUG:Open quote is expected for attribute "{1}" associated with an element type "id".
BUG原因:Mybatis的xml文件中id缺少双引号: 正确的应该是:
- 如何使用impdp导入oracle数据库文件
1.首先,安装好oracle数据库. 2.使用sqlplus进入sysdba权限,sqlplus "/as sysdba", 例如: 3.创建用户framework,例如: CRE ...
- Codeforces Round #544 (Div. 3) 题解
Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization 题目链接:https://codeforces.com/contest/113 ...
- HDU4738:Caocao's Bridges(求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 微服务学习三:springboot与springcloud集成之Eurake的使用(server端,client端)
这个多亏了网站上的一个大神的博客: http://blog.csdn.net/forezp/article/details/70148833 强烈推荐学习: 1.springcloud是什么,这个大家 ...
- aos.js让页面滚动变得丰富
(转)<script src="js/jquery-2.1.1.min.js" type="text/javascript"></script ...
- UVA 1638 Pole Arrangement
https://vjudge.net/problem/UVA-1638 题意: n根长度分别为1,2,3,4……n的木棍 将这些木棍竖着排成一列 问从左边看能看到L根,从右边看能看到R根的方案数 将木 ...
- NOIP2006 数列
codevs 1141 数列 http://codevs.cn/problem/1141/ 2006年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目描述 ...
- LightOJ 1058 - Parallelogram Counting 几何思维
http://www.lightoj.com/volume_showproblem.php?problem=1058 题意:给你顶点,问能够成多少个平行四边形. 思路:开始想使用长度来扫描有多少根,但 ...