[SP1825] Free tour II】的更多相关文章

/* ----------------------- [题解] https://www.luogu.org/blog/IRving1-1/solution-sp1825 ----------------------- O(Nlog^2)做法,vjudge上写的是时限100ms,过2e5数据 ----------------------- 统计tmp[i]为有i个黑点的最长路径,进行转移 合并的顺序很巧妙,也很重要,这里倒序枚举当前子树的j(tmp[j]),则可以做到控制维护之前子树cur(max…
题目链接 Free tour II 题意:有$N$个顶点的树,节点间有权值, 节点分为黑点和白点. 找一条最长路径使得 路径上黑点数量不超过K个 这是树的点分治比较基本的题,涉及树上启发式合并……仰望了黄学长的博客之后稍微有点明白了(还没有很深入地理解) #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b)…
# \(SP1825\) 看到没有人用老师的办法,于是自己写一下思路 思路第一步:排除旧方法 首先这道题和\(4178\)不一样,因为那道题是计数,而这道题是求最值,最值有个坏处,就是对于来自相同子树的信息没法高效剔除,比如容斥用不了,举例来说,对于这道题,如果我们继续用尺取法维护黑点个数,对于一组刚好使\(cnt_l+cnt_r\leq k\)的\(l,r\),且\([l+1,r]\)所在子树都与\(l\)不同时就可以选取\(l~and~x\in [l+1,r]\),我们要使\(dis_l+d…
题意翻译 给定一棵n个点的树,树上有m个黑点,求出一条路径,使得这条路径经过的黑点数小于等于k,且路径长度最大 Code: #include <bits/stdc++.h> using namespace std; #define pr pair<int, int> #define mp make_pair const int maxn = 2000003; const int inf = 1000000000; void setIO(string a) { string in =…
http://www.spoj.com/problems/FTOUR2/ 先前看了一会题解就自己yy出来了...对拍过后交tle.................. 自己造了下大数据........tle......................... what? 首先来看经过当前点的路径: 设g[x,i]表示第x个孩子能得到的路径上黑点最多有i个(注意是最多)的最大长度,因为遍历的节点最坏为n个(第一层),因此在每一层都是$O(n)$的,可以承受. 考虑转移答案 $$ans[x]=max\{…
http://www.spoj.com/problems/FTOUR2/ After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, Travel Agent SPOJ goes on with another discount tour. The tour will be held on ICPC island, a miraculous one on…
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! Description After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, Travel Agent SP…
After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, Travel Agent SPOJ goes on with another discount tour. The tour will be held on ICPC island, a miraculous one on the Pacific Ocean. We list N places (…
Description 有些黑点,问你选择不超过 \(k\) 个黑点的路径,路径权值最大是多少. Sol 点分治. 这是qzc的论文题,不过我感觉他的翻译好强啊...我还是选择了自己去看题目... 点分治每次至少分一半,所以层数不超过过 \(logn\) 每次分治只考虑过根节点的情况. 我们想想如何统计答案. \(f[i][j]\) 表示 \(i\) 节点的子树拥有 \(j\) 个黑点最大的边权. \(g[i][j]\) 表示 \(i\) 节点的子树拥有不超过 \(j\) 个黑点的最大边权. \…
题意 luogu的翻译 给定一棵n个点的树,树上有m个黑点,求出一条路径,使得这条路径经过的黑点数小于等于k,且路径长度最大 Sol 点分治辣 如果是等于\(k\)的话,开个桶取\(max\)就好了 而小于等于\(k\),就可以把桶换成树状数组,求前缀\(max\) 很慢能过 # include <bits/stdc++.h> # define RG register # define IL inline # define Fill(a, b) memset(a, b, sizeof(a))…