![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划之树形DP
等我学会后缀自动机
侠影之谜
展开
-
Codeforces Round #646 (Div. 2) E. Tree Shuffling
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#defin.原创 2020-06-12 11:19:27 · 215 阅读 · 0 评论 -
CodeForces 239E World Eater Brothers (DP)
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l,m...原创 2020-04-09 23:26:09 · 124 阅读 · 0 评论 -
HDU 5293 Tree chain problem (树链剖分+LCA+树形DP)
#include<bits/stdc++.h>using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000") #define debug cout<<"YES\n";#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#de...原创 2020-03-21 11:34:28 · 137 阅读 · 0 评论 -
HDU 6540 Neko and tree(树形DP+思维)
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l,m...原创 2020-02-07 18:31:52 · 236 阅读 · 0 评论 -
HDU 5593 ZYB's Tree (树形DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5593#pragma comment(linker,"/STACK:1024000000,1024000000")#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(...原创 2018-10-19 08:32:08 · 153 阅读 · 0 评论 -
HDU 4679 Terrorist’s destroy (树形DP+树的直径)*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4679#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll lon...原创 2018-10-23 18:58:27 · 124 阅读 · 0 评论 -
Codeforces Round #525 (Div. 2)E.(树形DP+贪心)
题目链接:http://codeforces.com/contest/1088/problem/F#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll __in...原创 2018-12-05 23:02:15 · 157 阅读 · 2 评论 -
Gym 101102L Starry Night (树形DP+贪心)
题目链接:http://codeforces.com/gym/101102/problem/L#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long lo...原创 2019-02-09 08:31:51 · 153 阅读 · 0 评论 -
CSU 1811 Tree Intersection (map启发式合并+树形DP)
题目链接:http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=1811题目大意:给定一颗树,树上每个节点都有颜色,问对于每条边,其两端子树颜色集合交集的大小。题目分析: 相比于上次用线段树动态开点类似的方法来做合并,这次用map做启发式合并,这样的复杂度会因为每次都合并小的而降维。这道题同时还嵌套着树形D...原创 2019-02-24 09:36:53 · 158 阅读 · 0 评论 -
CSU 1811 Tree Intersection (树形DP思想+动态开点/主席树思想+启发式合并)
题目链接:http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=1811题目大意:给定一颗树,树上每个节点都有颜色,问对于每条边,其两端子树颜色集合交集的大小。 题目分析:这道题我是看题解才明白的,算是启发式合并的一个入门练习吧。首先想说这道题其实混合了不少思想在里面,我大致觉得有树形DP,线段树/主席树,...原创 2019-02-21 13:16:12 · 175 阅读 · 0 评论 -
Codeforces Round #551 (Div. 2)D D. Serval and Rooted Tree(树形DP+贪心)*
题目链接:http://codeforces.com/problemset/problem/1153/D题目大意给定一颗树结构,每个节点上设置了max和min标志,意味着该节点的值取其son的最大/最小值,而叶节点上的数取值为1到叶节点总个数并且各不相同.要求根节点值最大是多少.题目分析思考dp值,那么毫无疑问dp转移关系核心在min和max函数之间,考虑到...原创 2019-04-18 19:37:25 · 102 阅读 · 0 评论 -
CodeForces 219D Choosing Capital for Treeland (树形DP)
#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#define lrt int l,int r,int rt#define lson l...原创 2019-05-05 13:06:11 · 111 阅读 · 0 评论 -
2019 西安邀请赛 And And And(计数+树形DP)
题目链接:https://www.jisuanke.com/contest/2625#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define ll long long#...原创 2019-05-26 19:52:47 · 197 阅读 · 0 评论 -
HDU 5325 Crazy Bobo (树形DP+思维)*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5325#pragma comment(linker, "/STACK:102400000,102400000")#include<cstdio>#include<cstring>#include<vector>#include<algorithm&...原创 2018-10-14 18:03:04 · 135 阅读 · 0 评论 -
HDU 5148 Cities (树形DP)*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5148#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x...原创 2018-10-13 19:58:58 · 106 阅读 · 0 评论 -
UVA 1220 Party at Hali-Bula (树状DP+记忆化搜索)
Dear Contestant, I’m going to have a party at my villa at Hali-Bula to celebrate my retirement from BCM. I wish I could invite all my co-workers, but imagine how an employee can enjoy a party when he ...原创 2018-07-30 11:01:02 · 139 阅读 · 0 评论 -
UVA 1218 Perfect Services (树形DP经典)*
A network is composed of N computers connected by N −1 communication links such that any two computers can be communicated via a unique route. Two computers are said to be adjacent if there is a commu...原创 2018-08-01 06:53:33 · 148 阅读 · 0 评论 -
Codeforces 161D Distance in Tree ( 树形DP )
A tree is a connected graph that doesn't contain any cycles.The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.You are given a tree wi...原创 2018-08-10 12:36:32 · 450 阅读 · 0 评论 -
Codeforces round 294E Shaass the Great (树形DP+节点扫描式DP)
The great Shaass is the new king of the Drakht empire. The empire has n cities which are connected by n - 1 bidirectional roads. Each road has an specific length and connects a pair of cities. There's...原创 2018-08-14 16:33:31 · 132 阅读 · 0 评论 -
Codeforces 700B - Connecting Universities
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town.In Treeland there are 2k universities which are locate...原创 2018-08-07 10:38:43 · 193 阅读 · 0 评论 -
HDU 6446 Tree and Permutation (树形DP经典)
Tree and Permutation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 541 Accepted Submission(s): 182 Problem Description...原创 2018-08-26 11:13:08 · 763 阅读 · 0 评论 -
HDU 4705 Y (树形DP+计数)*
YTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2865 Accepted Submission(s): 835 Problem Description Sample Input 4 1...原创 2018-08-23 14:39:26 · 145 阅读 · 0 评论 -
HDU 4616 Game (树形DP+枚举思维方法)*
GameTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2520 Accepted Submission(s): 857 Problem Description Nowadays, there are more an...原创 2018-08-31 20:02:21 · 225 阅读 · 0 评论 -
HDU 5593 ZYB's Tree (树形DP)
ZYB's Tree Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 787 Accepted Submission(s): 265 Problem Description ZYB h...原创 2018-08-24 20:59:19 · 210 阅读 · 0 评论 -
HDU 4661 Message Passing (树形DP+组合数学知识+拓扑排序计数思维)*
Message PassingTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1461 Accepted Submission(s): 541 Problem DescriptionThere are n peo...原创 2018-08-29 17:58:31 · 336 阅读 · 0 评论 -
HDU 5379 Mahjong tree (树形DP+组合数学)*
Mahjong treeTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1935 Accepted Submission(s): 651 Problem DescriptionLittle sun is an arti...原创 2018-09-05 00:02:20 · 126 阅读 · 0 评论 -
HDU 4123 Bob’s Race (树形DP+RMQ维护极值)*
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4123#include<bits/stdc++.h>using namespace std;#define debug puts("YES");#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)#define read(x...原创 2018-10-13 16:58:05 · 196 阅读 · 0 评论