Description

Input
Output
Sample Input
5
1 3
5 2
4 3
3 5
Sample Output
2
Hint
【数据规模】
1 ≤ N ≤ 10000
这道题不是最水的树形DP吗?
只不过题意比较难懂一点。
翻译出来,草地就是一棵树。
然后就成为了树的最小支配集问题。
可以贪心,
可以DP。
附上我的DP代码:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
struct node{
int to;
int next;
}w[20005];
int cnt=1;
int h[10005];

本文介绍了一种树形动态规划(DP)问题及其解决方案,通过实例详细解析了如何运用DP和贪心策略求解树的最小支配集问题。同时提供了两种实现代码,一种基于DP,另一种为更简洁的贪心算法。
最低0.47元/天 解锁文章
1370

被折叠的 条评论
为什么被折叠?



