CF1249F Maximum Weight Subset】的更多相关文章

CF1249F Maximum Weight Subset 洛谷评测传送门 题目描述 You are given a tree, which consists of nn vertices. Recall that a tree is a connected undirected graph without cycles. Example of a tree.Vertices are numbered from 11 to nn . All vertices have weights, the…
题意:给定一棵n个点带点权的树,要求从中选出一个点集,使得这些点两两之间距离都大于K,求最大点权和 n,K<=2e2,1<=a[i]<=1e5 思路:树形DP显然可做,极限是n方,然而贪心也是,还比dp好写 可以用寒假camp里cls差不多的想法 从深度大的向上贪心,暴力维护对答案的贡献,即如果贡献大于0就取,并将距当前点距离<=K的贡献减去当前点 评论区甚至有红名大佬做到了线性复杂度 #include<bits/stdc++.h> using namespace st…
题目链接: http://codeforces.com/contest/1249/problem/F 题意: 一棵树的每个节点有个权值,选择一个节点集,使得任意点对的距离大于$k$ 求最大节点集权值,节点集权值为节点集中节点权值和 数据范围: $1\leq n \leq 200$ $1\leq k \leq 200$ 分析: 定义$dp[v][i]$,代表在$v$这颗子树中,被选择的点最小深度恰好是$i$的最大答案 初始状态$dp[v][0]=a[v]$,这是没有子树的情况,然后再逐个添加子树…
传送门 设 $f[x][i]$ 表示 $x$ 的子树中,离 $x$ 最近的选择的节点距离为 $i$ 的合法方案的最大价值 设 $val[x]$ 表示节点 $x$ 的价值,首先有 $f[x][0]=val[x]$ 那么考虑子树的合并,有 $f[x][min(i,j+1)]=max(f[x][min(i,j+1)],f[x][i]+f[v][j])$ 注意此时 $f[x][i]$ 不能包括 $v$ 的贡献,这个可以搞个 $tmp$ 存一下新的 $f[x]$,最后统一覆盖掉即可 然后答案就是 $f[r…
题意 在一颗有点权的树上,选若干个点,使得这些点两两距离大于k,且点权和最大 思路 贪心的取比较大的值即可 将所有点按照深度从大到小排序,如果当前点点权\(a[i]\)大于0,则将距离为k以内的所有点减\(a[i]\) 代表取了当前点,为答案贡献\(a[i]\) 如果下面又扫到大于零的点权,说明那个点比这个大,于是取那个 复杂度\(O(n^2)\) 代码 int n,k; int a[maxn],b[maxn]; vector<int>v[maxn]; int ans; int dep[max…
题:https://codeforces.com/contest/1249/problem/F 题意:给一颗树,边权为1,节点有点权,问取到一个点集,俩俩之间路径超过k,是点权和最大 思路:贪心地取点,先将点按照深度经行排序,每一次,取一个点权大于0的点,然后对于这个点bfs出去的路径小于k的点减去当前点的a[u],然后将a[i]加入到ans中 #include<bits/stdc++.h> using namespace std; #define fo(i,a,b) for(int i=a;…
CF1257F Make Them Similar $solution:$ 折半搜索后考虑如何维护两个数组的和,可以将 $A$ 中每个数减 $A_1$ ,$B$ 中每个数被减 $B_1$ ,$map$ 维护一下即可. #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<map> #include<vector> using…
A - Yet Another Dividing into Teams 题意:n个不同数,分尽可能少的组,要求组内没有两个人的差恰为1. 题解:奇偶分组. int a[200005]; void test_case() { int n; scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int ans = 1; for…
题目传送门 A .Yet Another Dividing into Teams sol:原先是用比较复杂的方法来解的,后来学弟看了一眼,发现不是1就是2,当出现两个人水平相差为1就分成两组,1组全是奇数,1组全是偶数,必然符合题意. 思维 #include "bits/stdc++.h" using namespace std; #define debug puts("what the fuck"); typedef long long LL; typedef p…
You are given a connected weighted graph with n vertices and m edges. The graph doesn't contain loops nor multiple edges. Consider some edge with id i. Let's determine for this edge the maximum integer weight we can give to it so that it is contained…