Contestants Division   Description In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and students will be able to compete at their own universities. However there’s one problem. Due to the high cost of t…
Contestants Division Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10704   Accepted: 3004 Description In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and students will be able to compete…
<题目链接> 题目大意:给你一棵树,让你找一条边,使得该边的两个端点所对应的两颗子树权值和相差最小,求最小的权值差. 解题分析: 比较基础的树形DP. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; #define INF 0x7fffffff7fffffff #define clr(a,b) memset…
题目链接 题意很扯,就是给一棵树,每个结点有个值,然后把图劈成两半,差值最小,反正各种扯. 2B错误,导致WA了多次,无向图,建图搞成了有向了.... #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define LL __int64 struct node {…
POJ 2378 Tree Cutting:题意 求删除哪些单点后产生的森林中的每一棵树的大小都小于等于原树大小的一半 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; ; <<; int t,n; int f[maxn]={}; int vis[maxn]={};…
Annoying problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 Description Coco has a tree, whose vertices are conveniently labeled by 1,2,-,n. There are m chain on the tree, Each chain has a certain weight. Coco would like to pick out some ch…
Balancing Act Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14550   Accepted: 6173 Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the tree yields a forest: a collection of one or m…
题目链接:http://poj.org/problem?id=2342 Description There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation forms a tree…
学习大佬:树的直径求法及证明 树的直径 定义: 一棵树的直径就是这棵树上存在的最长路径. 给定一棵树,树中每条边都有一个权值,树中两点之间的距离定义为连接两点的路径边权之和.树中最远的两个节点之间的距离被称为树的直径,连接这两点的路径被称为树的最长链.后者通常也可称为直径,即直径是一个数值概念,也可代指一条路径. 求法: 一.树形dp 时间复杂度:O( n ): 优点:代码量少实现方便. 不足:不容易记录路径. 实现过程: 状态:d[ x ] 以当前结点 x 为根的 子树的直径. 我们枚举每一个…
题目链接 题意: 有n个点的一棵树.其中树上有m条已知的链,每条链有一个权值.从中选出任意个不相交的链使得链的权值和最大. 思路: 树形DP.设dp[i]表示i的子树下的最优权值和,sum[i]表示不考虑i点时子树的最优权值和,即(j是i的儿子),显然dp[i]>=sum[i].那么问题是考虑i点时dp[i]的值是多少,假设有一条链通过i,且端点a和b都在i的子树里,即LCA(a,b)=i,如果考虑加上这条链的权值,那么a->i, b->i的路上的点v都不能有链经过它们(题目要求链不相交…
题目链接 树形DP很弱啊,开始看题,觉得貌似挺简单的,然后发现貌似还可以往回走...然后就不知道怎么做了... 看看了题解http://www.cnblogs.com/wuyiqi/archive/2012/01/09/2316758.html画画题解中的三种情况,还是可以理解的. 设dp[0][s][j]表示从s(当前根节点)出发,走 j 步,回到s所能获得的最大权值 dp[1][s][j]表示从s(当前根节点)出发,走j步,不回到s所能获得的最大权值 现在我们就可以分配背包容量了:父节点与子…
给出一棵树,编号为1~n,给出数m 漂亮mm连续n天锻炼身体,每天会以节点i为起点,走到离i最远距离的节点 走了n天之后,mm想到知道自己这n天的锻炼效果 于是mm把这n天每一天走的距离记录在一起,成为一段长度为n的数列 现在mm想要从这数列中选出一个连续的区间,要求这个区间的max-min<=m 输出最长的区间 做了一个下午 思路: 分成2个部分: 1.求出数列,即对于一棵树,求出每一个节点能到达的最远距离 2.对于这段数列,选出一个区间,使得区间的max-min<=m,并且使得区间长度尽量…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5293 题意: 给你一些链,每条链都有自己的价值,求不相交不重合的链能够组成的最大价值. 题解: 树形dp, 对于每条链u,v,w,我们只在lca(u,v)的顶点上处理它 让dp[i]表示以i为根的指数的最大值,sum[i]表示dp[vi]的和(vi为i的儿子们) 则i点有两种决策,一种是不选以i为lca的链,则dp[i]=sum[i]. 另一种是选一条以i为lca的链,那么有转移方程:dp[i]=…
Walking Race Time Limit: 10000MS   Memory Limit: 131072K Total Submissions: 4123   Accepted: 1029 Case Time Limit: 3000MS Description flymouse’s sister wc is very capable at sports and her favorite event is walking race. Chasing after the championshi…
Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The cows didn't have time to rebuild any extra roads, so now there is exactly one way to get from any g…
题目链接: POJ 3345 Bribing FIPA 题意: 一个国家要参加一个国际组织,  需要n个国家投票,  n个国家中有控制和被控制的关系, 形成了一颗树. 比如: 国家C被国家B控制, 国家B被国家A控制, 那么B , C 会跟着A投同一家国家. 而要有些国家给它投票, 就得用若干钻石去贿赂那些国家. 最后问, 要到至少有m个国家投它的票, 最少需要多少钻石. 分析: 对于每一个结点只有两种状态, 选与不选, 所以dp方程里加上一维即可. dp[i][j][k], 表示在i的子结点中…
题目链接:http://poj.org/problem?id=2342 题意:一家公司有1 <= N <= 6 000个职工,现要组织一些职工参加晚会,要求每个职工和其顶头上司不能同时参加晚会,并且每个职工有一个enjoy值,问选取的职工的最大enjoy总和为多少? 输入N个职工各种的enjoy值,和L K表示K是L的顶头上司: 思路:建图之后DFS,dp[u][1] :u去时,以u为根的子树最大enjoy值,dp[u][0]:u不去时,以u为子树的enjoy值: 则dp[u][1] += d…
Apple Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9808   Accepted: 3260 Description Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amoun…
http://poj.org/problem?id=2152 题意: n个节点组成的树,要在树一些点上建立消防站,每个点建站都有个cost[i],每个点如果不在当前的点上建站,也要依赖其他的消防站,并且距离不超过limit[i].求符合上述条件的最小费用建站费用. 思路: 感觉有点无从下手,如果不会的话可以先看一下一张一弛,解题之道这篇论文. 其实说白了,就是暴力枚举. 先设立一个辅助数组$best$,$best[u]$表示以u及其子树的最小费用,$dp[u][j]$表示u依赖j节点时(也就是j…
Rebuilding Roads   Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The cows didn't have time to rebuild any extra roads, so now there is exactly one wa…
题意: 求n个节点的树中哪个节点删除以后得到的最大连通分量最小. 分析:同上题 #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include &…
题意: n个节点的树,删除一个点,得到的最大联通分支大小不大于总节点数的一半,求这样点的集合 分析:和上题一样 #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <strin…
TELE Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4863   Accepted: 2673 Description A TV-network plans to broadcast an important football match. Their network of transmitters and users can be represented as a tree. The root of the tre…
Tree Cutting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4834   Accepted: 2958 Description After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 <= N <= 10,000) barns at an incredible…
Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9105   Accepted: 4122 Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The…
Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers d…
http://poj.org/problem?id=3162 题意 :  一棵n个节点的树.wc爱跑步,跑n天,第i天从第i个节点开始跑步,每次跑到距第i个节点最远的那个节点(产生了n个距离),现在要在这n个距离里取连续的若干天,使得这些天里最大距离和最小距离的差小于M,问怎么取使得天数最多?   每个点的最大距离和之前http://acm.hdu.edu.cn/showproblem.php?pid=2196这道题一样 (就是求每个子树的最长子链,次长子链,然后求经过父亲节点能达到的最大值,比…
题意:有n个人,接下来n行是n个人的价值,再接下来n行给出l,k说的是l的上司是k,这里注意l与k是不能同时出现的 链接:点我 dp[i][1] += dp[j][0], dp[i][0] += max{dp[j][0],dp[j][1]};其中j为i的孩子节点. 第二次做感觉已经很水了 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<…
版权声明:本文为博主原创文章,未经博主允许不得转载. Rebuilding Roads Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8227   Accepted: 3672 Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrib…