![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DP——树DP图DP
onepointo
欲言又止
展开
-
BZOJ 4726 [POI 2017] 树DP 解题报告
4726: [POI2017]Sabota?Description某个公司有n个人, 上下级关系构成了一个有根树。其中有个人是叛徒(这个人不知道是谁)。对于一个人, 如果他下属(直接或者间接, 不包括他自己)中叛徒占的比例超过x,那么这个人也会变成叛徒,并且他的所有下属都会变成叛徒。你要求出一个最小的x,使得最坏情况下,叛徒的个数不会超过k。Input第一行包含两个正整数n,k(1<=k<=n<=5原创 2017-09-22 19:13:49 · 285 阅读 · 0 评论 -
BZOJ 1131 [POI 2008] 解题报告
1131: [POI2008]StaDescription给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大Input给出一个数字N,代表有N个点.N<=1000000 下面N-1条边.Output输出你所找到的点,如果具有多个解,请输出编号最小的那个.Sample Input8 1 4 5 6 4 5 6 7 6 8 2 4 3 4Sample Output7原创 2017-09-22 14:28:47 · 215 阅读 · 0 评论 -
BZOJ 3727 PA2014 树DP 解题报告
3727: PA2014 Final ZadanieDescription吉丽YY了一道神题,题面是这样的:“一棵n个点的树,每条边长度为1,第i个结点居住着a[i]个人。假设在i结点举行会议,所有人都从原住址沿着最短路径来到i结点,行走的总路程为b[i]。输出所有b[i]” 吉丽已经造好了数据,但熊孩子把输入文件中所有a[i]给删掉了。你能帮他恢复吗?Input第一行一个整数n(2<=n<=30原创 2017-09-22 16:41:20 · 193 阅读 · 0 评论 -
Codeforces 459E 图上DP 解题报告
E. Pashmak and GraphPashmak’s homework is a problem about graphs. Although he always tries to do his homework completely, he can’t solve this problem. As you know, he’s really weak at graph theory; so原创 2017-10-18 20:57:06 · 376 阅读 · 0 评论 -
Codeforces 461B 树DP 解题报告
B. Appleman and TreeAppleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of原创 2017-10-18 21:52:11 · 367 阅读 · 0 评论 -
Codeforces 711C 树DP 解题报告
C. Bear and Tree JumpsA tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He l原创 2017-10-27 17:20:38 · 240 阅读 · 0 评论 -
BZOJ 4102 [Usaco2015 Open] 图上DP 解题报告
4102: [Usaco2015 Open]BessieDescription为了庆祝贝茜的生日,FJ给她吃草的自由. N块草地,标号1到N(1<=N<=1000),草地有营养价值.当贝茜走到这个草地,可以获得等于这块草地的营养价值的能量. 每块草地最多有10条双向边,每走一条边,贝茜花费E的能量. 贝茜拿可以从任何地方出发,当她不能获得更多的能量的时候她就会停止. 然而因为贝茜挑食,她每次不会吃低原创 2017-10-29 14:48:50 · 311 阅读 · 0 评论 -
BZOJ 5072 [Lydsy 十月月赛] 树DP 解题报告
Problem Statement小A 成为了一个园艺家!他有一棵n 个节点的树(如果你不知道树是什么,请看Hint 部分)。他不小心打翻了墨水瓶,使得树的一些节点被染黑了。小A 发现这棵染黑了的树很漂亮,于是想从树中取出一个x 个点的联通子图,使得这些点中恰有y 个黑点,他想知道他的愿望能否实现。可是他太小,不会算,请 你帮帮他。【解题报告】考虑转化才成树上背包的形式,发现对于每一个x都有一个y原创 2017-10-31 19:33:10 · 294 阅读 · 0 评论 -
2017.11.2 树上期望DP 解题报告
题目描述给你一棵包含个n点的有根树,点的标号是1…n,在t=1时( t表示时间),你在1号点,接下来,你会随机跑到当前点相邻的点,然后继续这个过程,直到访问了所有的点,已从一个点到另一个点需要的时间是1秒,那么问题来了,请问在这个随机过程中,对于每个节点,冬雪第一次访问的期望时间是多少?输入数据:3 1 2 2 3输出数据:1.000 2.000 5.000【解题报告】 代码如下:#i原创 2017-11-02 20:14:41 · 458 阅读 · 0 评论 -
BZOJ 1907 树DP 解题报告
1907: 树的路径覆盖Description Input Output Sample Input1 7 1 2 2 3 2 4 4 6 5 6 6 7Sample Output3【解题报告】 首先将所有的链都考虑成以链上所有点的LCA为转折点的V字形 那么点有两种:转折点和非转折点 因此我们选择两种状态进行转移:还会和父亲组成链的状态和成为转折点的状态代码如下原创 2017-09-22 14:00:08 · 265 阅读 · 0 评论 -
BZOJ 4033 [HAOI 2015] 树DP 解题报告
4033: [HAOI2015]树上染色Description有一棵点数为N的树,树边有边权。给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并将其他的N-K个点染成白色。将所有点染色后,你会获得黑点两两之间的距离加上白点两两之间距离的和的收益。问收益最大值是多少。Input第一行两个整数N,K。接 下来N-1行每行三个正整数fr,to,dis,表示该树中存在一条长度为di原创 2017-09-22 11:03:16 · 202 阅读 · 0 评论 -
BZOJ 3566 [SHOI 2014] 树上期望DP 解题报告
3566: [SHOI2014]概率充电器Description著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品——概率充电器:“采用全新纳米级加工技术,实现元件与导线能否通电完全由真随机数决定!SHOI 概率充电器,您生活不可或缺的必需品!能充上电吗?现在就试试看吧!”SHOI 概率充电器由 n-1 条导线连通了 n 个充电元件。进行充电时,每条导线是否可以导电以概率决定,每一原创 2017-09-22 09:04:18 · 432 阅读 · 0 评论 -
BZOJ 2435 [Noi 2011] 树DP 解题报告
2435: [Noi2011]道路修建Description在 W 星球上有 n 个国家。为了各自国家的经济发展,他们决定在各个国家之间建设双向道路使得国家之间连通。但是每个国家的国王都很吝啬,他们只愿意修建恰好 n – 1条双向道路。 每条道路的修建都要付出一定的费用, 这个费用等于道路长度乘以道路两端的国家个数之差的绝对值。例如,在下图中,虚线所示道路两端分别有 2 个、4个国家,如果该道路长度原创 2017-09-21 14:05:38 · 291 阅读 · 0 评论 -
留着以后慢慢做的树形DP(题表)
树型动态规划转载 2017-05-19 20:39:16 · 383 阅读 · 0 评论 -
Codeforces Round 430 (Div 2) C
C. Ilya And The TreeIlya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very interesting tree rooted at vertex 1. There is an integer number written on each v原创 2017-08-30 21:25:28 · 184 阅读 · 0 评论 -
Codeforces Round #428 (Div 2) C
C. JourneyThere are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the fi原创 2017-08-13 16:42:08 · 197 阅读 · 0 评论 -
Codeforces 219D 树DP 解题报告
D. Choosing Capital for TreelandThe country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we d原创 2017-09-21 16:44:22 · 237 阅读 · 0 评论 -
Codeforces 815 C 树形依赖背包 解题报告
C. Karen and SupermarketOn the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited.原创 2017-10-17 21:34:50 · 500 阅读 · 0 评论 -
POJ 1655 树的重心 解题报告
Balancing ActDescriptionConsider 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 more trees. Define the balance of a node原创 2017-09-22 08:28:00 · 222 阅读 · 0 评论 -
2017.11.3 树上期望DP 解题报告
题目描述梦游中的你来到了一棵N个节点的树上. 你一共做了Q个梦, 每个梦需要你从点u走到点v之后才能苏醒, 由于你正在梦游, 所以每到一个节点后,你会在它连出去的边中等概率地选择一条走过去, 为了确保第二天能够准时到校, 你要求出每个梦期望经过多少条边才能苏醒. 为了避免精度误差, 你要输出答案模109+7的结果.输入格式第一行两个整数分别代表N和Q. 接下来N-1行, 每行两个整数u, v代表树中原创 2017-11-03 16:32:27 · 606 阅读 · 0 评论