树型dp
丿残念灬
这个作者很懒,什么都没留下…
展开
-
CodeForces-349D Apple Tree(树型dp)
D. Apple Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with n vertices.原创 2016-08-19 01:40:21 · 475 阅读 · 0 评论 -
Nowcoder-2018ACM多校训练营(第二场)H travel
时间限制:C/C++ 2秒,其他语言4秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述 White Cloud has a tree with n nodes.The root is a node with number 1. Each node has a value.White Rabbit wants to tra...原创 2018-07-24 09:48:43 · 276 阅读 · 0 评论 -
Codeforces-815C Karen and Supermarket(树型dp+背包)
传送门:Codeforces-816E题意:有n个物品,购买第i个物品需要花费Ai元,每个物品都有相应的折扣劵,如果使用折扣劵买第i个物品可以折扣Bi元,但如果要使用第i个折扣劵必须要先使用第pre[i]个折扣劵(第一个折扣劵没有限制),现在有V元,问最多能买多少物品题解:树型dp+背包设dp[u][cnt][0/1]为以u为根的子树中,购买cnt个物品时的最小花费,0表示第u个物品不原创 2017-08-21 21:55:43 · 373 阅读 · 0 评论 -
Codeforces-734E Anton and Tree(树的直径)
E. Anton and Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAnton is growing a tree in his garden. In原创 2017-08-12 19:26:29 · 345 阅读 · 0 评论 -
HDU-6035 Colorful Tree(树型dp)
Colorful TreeTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 512 Accepted Submission(s): 189Problem DescriptionThere is a tree原创 2017-07-26 10:38:16 · 1486 阅读 · 0 评论 -
HDU-4705 Y(树型dp)
传送门:HDU-4705题意:一棵n个节点的树,要求统计所有满足以下条件的三元组的个数:①ABC是数上的节点;②ABC之间不存在一条连通这3个节点的简单路径题解:树型dpdp以u为根节点的子树时,计算2个状态:①dp1[u]:子树中LCA为u的三元组的个数;②num[u]:子树中LCA(x,y)!=x且LCA(x,y)!=y的二元组的个数那么子树u对答案的贡献为:dp1[u原创 2017-08-10 00:28:24 · 276 阅读 · 0 评论 -
HDU-4123 Bob’s Race(树型dp+RMQ)
传送门:HDU-4123题意:有n个点组成一棵树编号为1~n,定义一个点的最远距离为从该点出发的最长简单路径,有m次询问:求最大区间长度,使得区间内所有点最远距离的最大值-最远距离的最小值题解:先2次dfs求出每个点的最远距离,再用尺取法+RMQ找出最长区间#includeusing namespace std;typedef long long LL;const int MX原创 2017-08-10 00:14:40 · 438 阅读 · 0 评论 -
HDU-4714 Tree2cycle(树型dp)
传送门:HDU-4714题意:一棵树有n个节点,有2种操作:①删除1条边;②添加1条边。每次操作花费为1,要求用最小花费使得这棵树变成一个环:整个图有n条边,每个点的度为2且构成1个联通块题解:树型dpdp以u为根节点的子树时时记录2种状态:①将子树变成一条链且其中一端为u的最小花费;②将子树变成一条链的最小花费#pragma comment(linker, "/STACK:102原创 2017-08-10 00:20:17 · 407 阅读 · 2 评论 -
Gym-101353H Simple Path(树型dp)
传送门:https://odzkskevi.qnssl.com/86ae857f80d3f4ae7389f98461306080?v=1499831299题意:定义一棵树的价值为:这棵树上所有简单路径的长度之和,现在给出n个节点的树,边的权值为w,以1为根节点,问所有子树价值的和题解:树型dp设dp[u]为以u为根的子树的价值,sz[u]为以u为根的子树的节点数,v原创 2017-07-16 01:09:06 · 512 阅读 · 0 评论 -
HDU-5956 The Elder(树型dp+斜率优化)
Once upon a time, in the mystical continent, there is a frog kingdom, ruled by the oldest frog, the Elder. The kingdom consists of N cities, numbered from east to west. The 1-th city, which is located原创 2017-07-13 13:25:01 · 1309 阅读 · 0 评论 -
CodeForces-743D Chloe and pleasant prizes(树型dp)
传送门:http://codeforces.com/contest/743/problem/D题意:有n个点,编号为1~n,n个点构成以1为根节点的树,每个节点都有相应的权值,要求找出2个不相交的子树使得权值和最大题解:树型dp,对于每个点u,找出其权值最大的子树和权值次大的子树,如果两者都存在则将两者之和与ans比较,ans取较大值#include#include#include原创 2016-12-16 21:01:47 · 361 阅读 · 0 评论 -
CodeForces-1004E Sonya and Ice Cream(树型DP+RMQ)
E. Sonya and Ice Creamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSonya likes ice cream very much. She eats it even during p...原创 2018-08-23 19:20:29 · 339 阅读 · 0 评论