随笔分类 -  动态规划-树形DP

摘要:题面:https://www.luogu.org/problemnew/show/P2986 cpp Code: include include using namespace std; struct B { int t,ne,d; }a[200005]; int n,e,fr[100005],c[ 阅读全文
posted @ 2019-10-16 20:00 prestige 阅读(123) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problem/P1099 阅读全文
posted @ 2019-10-16 19:58 prestige 阅读(85) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problem/P2607 cpp 没有上司的舞会+环套树(破环为链)。。。 Code: include include include include include include include include using namespace 阅读全文
posted @ 2019-10-15 21:02 prestige 阅读(90) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problem/P5021 cpp 本题首先看到最小值最大就可以想到二分,即二分一个mid作为答案,设f[u]为以u为根的子树中,不选作赛道的边最大为多少,因为赛道的选定只有两种情况,一是继续连向根的父亲,二是从儿子到根再到儿子,那么f[v]+w = 阅读全文
posted @ 2019-10-14 13:20 prestige 阅读(101) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problem/P1351 cpp 本题可以直接枚举每个点所相连的点,因为子 父 子距离刚好是2,所以最大权值就由儿子中的权值最大值和权值次大值的乘积来提供,而和可以直接统计,最后乘2即可,因为联合权值的产生是成对的. Code: include i 阅读全文
posted @ 2019-09-30 06:14 prestige 阅读(165) 评论(0) 推荐(0)
摘要:```cpp 【题目描述】: 一个树由n个点,n 1条边组成,结点编号为1…n。树上任意两个点之间路径唯一。 定义一个点到一条路径的距离为该点到路径上最近的一个点需要经过的边的数量。 现在想知道怎样选两个点确定一条路径,使得距离这个路径最远的点尽量近。要求你输出距离路径最远的点距离路径的距离。 【输 阅读全文
posted @ 2019-09-24 13:14 prestige 阅读(147) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problem/P1273 阅读全文
posted @ 2019-07-25 12:58 prestige 阅读(122) 评论(0) 推荐(0)
摘要:题面:http://poj.org/problem?id=3398 cpp 本题是求树的最小支配集裸题。 Code: include include include include include include include using namespace std; const int N=10 阅读全文
posted @ 2019-07-25 12:41 prestige 阅读(93) 评论(0) 推荐(0)
摘要:题面:http://acm.hdu.edu.cn/showproblem.php?pid=1054 cpp 本题是求树的最小点覆盖裸题。 Code: include include include include include include include using namespace std 阅读全文
posted @ 2019-07-25 12:39 prestige 阅读(83) 评论(0) 推荐(0)
摘要:```cpp 题目描述 某大学有N个职员,编号为1~N。他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司。现在有个周年庆宴会,宴会每邀请来一个职员都会增加一定的快乐指数Ri,但是呢,如果某个职员的上司来参加舞会了,那么这个职员就无论如何也不肯来参加舞会了。所以 阅读全文
posted @ 2019-07-25 12:37 prestige 阅读(66) 评论(0) 推荐(0)
摘要:题面:http://poj.org/problem?id=1655 阅读全文
posted @ 2019-07-25 12:35 prestige 阅读(88) 评论(0) 推荐(0)
摘要:题面:http://poj.org/problem?id=2631 阅读全文
posted @ 2019-07-25 12:32 prestige 阅读(73) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2019-07-24 15:04 prestige 阅读(18) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problemnew/show/P3047 cpp Code: include using namespace std; const int root=1,MAXN=100001; struct rec{ int pre,to; }a[2 MAXN] 阅读全文
posted @ 2019-07-24 14:11 prestige 阅读(127) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problemnew/show/P2015 cpp 设f[u][i]表示u的子树上保留i条边,至多保留的苹果数目 那么状态转移方程也就显而易见了: f[u][i]=max(f[u][i],f[u][i−j−1]+f[v][j]+e[i].w)( 1≤ 阅读全文
posted @ 2019-07-23 14:19 prestige 阅读(125) 评论(0) 推荐(0)
摘要:题面:https://www.luogu.org/problemnew/show/P1040 cpp 本题即一个在树上做的区间dp,只不过中间枚举的断点k即为当前dp到的树的根节点,然后将当前区间分为两段,即为树上的左子树和右子树,不过要注意这里的k可以取到端点值,即k的取值范围为[i,j]因为一棵 阅读全文
posted @ 2019-07-16 13:50 prestige 阅读(151) 评论(0) 推荐(0)