随笔分类 - 动态规划--树形dp
摘要:题目 分析 凉凉。 答案是所有要经过的点到根所经过的边权和减去最大的边权。 代码 vector好慢啊 #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int maxn=105000
阅读全文
摘要:题目 分析 $ k=1 $ 时显然就是树的直径 $ k=2 $ 时怎么做呢? 做法是把一开始树的直径上的边的边权改成$ -1 $,那么当我们第二次用这些边做环时就抵消了一开始的贡献。 所以答案就是边的数量*2 - 一开始树的直径 - 后来树的直径 P.S. 第二次求树的直径时只能dp 代码 #inc
阅读全文
摘要:题目 题目 分析 带权值的树上最大独立集 代码 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn=6005; 4 int a[maxn], n, fa[maxn]; 5 vector<int> son[maxn];
阅读全文

浙公网安备 33010602011771号