HDU p1294 Rooted Trees Problem 解题报告】的更多相关文章

http://www.cnblogs.com/keam37/p/3639294.html keam所有 转载请注明出处 Problem Description Give you two definitions tree and rooted tree. An undirected connected graph without cycles is called a tree. A tree is called rooted if it has a distinguished vertex r c…
题目大意:求有n个节点的树有几种? 题解:http://www.cnblogs.com/keam37/p/3639294.html #include <iostream> typedef long long LL; using namespace std; LL f[41]; int cnt[41],n; LL C(LL n,LL m){ m=m<(n-m)?m:(n-m); LL ans=1; for(int i=1;i<=m;i++)ans=ans*(n-i+1)/i; ret…
[LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/unique-binary-search-trees-ii/description/ 题目描述: Given an integer n, generate all s…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题目意思:有 n 个气球从左到右排成一排,编号依次为1,2,3,...,n.给出 n 对 a, b,表示编号为 a ~b 的气球被涂过一次色.n 次之后,问所有气球被上色的次数分别是多少. 典型的树状数组题!这种是:每次修改一个区间,问的是最后每个点被修改的次数.要注意update() 函数对 a 处理 的时候,向上修改的过程中把不必要的区间都加了一遍.例如对a = 2时,update修改了c…
Unique Binary Search Trees II Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. 1         3     3      2      1 \      …
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 题目意思:给出一堆老鼠,假设有 n 只(输入n条信息后Ctrl+Z).每只老鼠有对应的weight 和 speed.现在需要从这 n 只老鼠的序列中,找出最长的一条序列,满足老鼠的weight严格递增,speed严格递减. 我们可以用一个结构体来保存老鼠的信息,包括weight, speed 以及 id(这个 id 是未排序之前的,为了输出最后信息).那么首先对 weight 进行递增排序,如…
题目链接:http://code.hdu.edu.cn/showproblem.php?pid=1879 这条题目我的做法与解决Constructing Roads的解法是相同的. 0 表示没有连通:1代表已连通.在已连通村庄的道路的基础上,找到扩展出来的最小生成树. #include <iostream> #include <algorithm> using namespace std; + ; int rep[maxe], vis[maxe]; struct sets { in…
题目链接:http://code.hdu.edu.cn/showproblem.php?pid=1233 并查集的运用, 实质就是求最小生成树.先对所有的村庄距离从小到大排序,然后判断村庄之间是否属于同一集合,不是则将距离相加.属于同一集合,说明村庄连成了环,就不符合树的定义了.这样扫描下来,就求得最小生成树了. 要特别注意的是,数组越界问题.这个得益于Dwylkz的指点.由于村庄最多假设为100,为了防止边数越界,数组应该开到100 * 100 (10000)左右. #include <ios…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数. 并查集的入门题,什么优化都无用到就可以直接过.实质上就是统计总共有多少个不相交的集合.比较可恶的是,题目中 There will be a blank line between two cases 是骗人的!!! #include <iostream> using namespace std; + ; int p[…
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划了一下,凭着直觉,竟然一次AC,那个兴奋啊 !^_^ !  好啦,不说废话. 这个题目被分类为 math 和 matrices ,数学还好理解,matrices,应该是母函数吧(不好意思的说,还没系统地学到),姑且让我分类到数学里吧.题目的意思是,给出一个水平长度 : 垂直长度的比例分别为 a:b…