当前位置: 首页 > news >正文

桂林尚品网络做的网站好不好营销网站的建造步骤

桂林尚品网络做的网站好不好,营销网站的建造步骤,安徽省建设行业安全协会网站,网站别人能打开我打不开题意 传送门 Codeforces 1856E2 PermuTree (hard version) 题解 可以独立考虑每一个固定的 p l c a ( u , v ) plca(u,v) plca(u,v) 对答案的贡献。可以观察到&#xff0c;对于 p p p 的每一棵子树&#xff0c;其所有节点在最优情况下仅有 a p < a v a_p < a_v ap…
题意

传送门 Codeforces 1856E2 PermuTree (hard version)

题解

可以独立考虑每一个固定的 p = l c a ( u , v ) p=lca(u,v) p=lca(u,v) 对答案的贡献。可以观察到,对于 p p p 的每一棵子树,其所有节点在最优情况下仅有 a p < a v a_p < a_v ap<av a p > a v a_p > a_v ap>av 两种可能。那么需要在值域上将子树的节点左右划分,那么需要求解所有子树的子集中,子树规模 s z v sz_v szv 的和最接近所有子树和的 1 / 2 1/2 1/2 的值 x x x,则对答案的贡献为 x ∗ ( s z p − 1 − x ) x * (sz_p - 1 - x) x(szp1x)。对于上述背包问题,满足 s z u + ⋯ + s z v = s z p − 1 sz_u + \cdots + sz_v = sz_p - 1 szu++szv=szp1,可以做到 O ( s z p s z p ) O(sz_p\sqrt{sz_p}) O(szpszp ),具体做法类似于二进制拆分,不断将相同的值合并,最终每一个不同的值仅有常数个,则不同的值数量为 O ( s z p ) O(\sqrt{sz_p}) O(szp )

若存在 s z v ∗ 2 ≥ s z p − 1 sz_v * 2 \geq sz_p - 1 szv2szp1,则无需进行背包。考虑最坏情况,即平衡的多叉树,容易观察到所有背包 DP 的复杂度为 O ( n n ) O(n\sqrt{n}) O(nn ), std::bitset 优化即可。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 1E6;template <int m = 1>
ll knapsack(int n, vector<int> &b) {if (m < n) {return knapsack<min(m * 2, N)>(n, b);}bitset<m + 1> bt;bt[0] = 1;for (int x : b) {bt |= bt << x;}int res = -1;for (int i = 0; i <= m; ++i) {if (bt[i] > 0) {if (res == -1 || abs(2 * res - n) > abs(2 * i - n)) {res = i;}}}return res;
}int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;vector<vector<int>> g(n);for (int i = 1; i < n; ++i) {int p;cin >> p;g[p - 1].push_back(i);}auto get = [&](vector<int> &a) -> ll {if ((int)a.size() < 2) {return 0;}int sum = 0, mx = 0;for (int x : a) {sum += x;mx = max(mx, x);}if (mx * 2 >= sum) {return (ll)mx * (sum - mx);}vector<int> b;vector<int> freq(sum + 1);for (int x : a) {freq[x] += 1;}for (int i = 1; i <= sum; ++i) {if (freq[i] > 0) {int d = (freq[i] - 1) / 2;freq[2 * i] += d;freq[i] -= d * 2;for (int j = 0; j < freq[i]; ++j) {b.push_back(i);}}}int x = knapsack(sum, b);return (ll)x * (sum - x);};vector<int> sz(n);ll res = 0;function<void(int)> dfs = [&](int v) {sz[v] = 1;vector<int> a;for (int u : g[v]) {dfs(u);a.push_back(sz[u]);sz[v] += sz[u];}res += get(a);};dfs(0);cout << res << '\n';return 0;
}

文章转载自:
http://bisayan.c7496.cn
http://uprisen.c7496.cn
http://haroseth.c7496.cn
http://raggee.c7496.cn
http://statutable.c7496.cn
http://nonsignificant.c7496.cn
http://jerrymander.c7496.cn
http://ironmaster.c7496.cn
http://cragginess.c7496.cn
http://nictheroy.c7496.cn
http://spoilt.c7496.cn
http://falcongentle.c7496.cn
http://southbound.c7496.cn
http://ergate.c7496.cn
http://aglare.c7496.cn
http://perjury.c7496.cn
http://liver.c7496.cn
http://subserous.c7496.cn
http://dina.c7496.cn
http://faucalize.c7496.cn
http://gatehouse.c7496.cn
http://scyphiform.c7496.cn
http://grannie.c7496.cn
http://comitia.c7496.cn
http://agromania.c7496.cn
http://fructifier.c7496.cn
http://cpc.c7496.cn
http://peculate.c7496.cn
http://chromium.c7496.cn
http://conceited.c7496.cn
http://parthenogenesis.c7496.cn
http://transignification.c7496.cn
http://leucemia.c7496.cn
http://floscule.c7496.cn
http://b2b.c7496.cn
http://smithcraft.c7496.cn
http://semicommercial.c7496.cn
http://antismoking.c7496.cn
http://moray.c7496.cn
http://cordate.c7496.cn
http://suttle.c7496.cn
http://walkathon.c7496.cn
http://shavetail.c7496.cn
http://powder.c7496.cn
http://instantiation.c7496.cn
http://koso.c7496.cn
http://selectionist.c7496.cn
http://iab.c7496.cn
http://penitentially.c7496.cn
http://vandalize.c7496.cn
http://calamus.c7496.cn
http://grubber.c7496.cn
http://quietly.c7496.cn
http://eagle.c7496.cn
http://apocalyptical.c7496.cn
http://cliquism.c7496.cn
http://contain.c7496.cn
http://klan.c7496.cn
http://ropedancer.c7496.cn
http://thornbush.c7496.cn
http://alfresco.c7496.cn
http://trowelman.c7496.cn
http://fiber.c7496.cn
http://incommode.c7496.cn
http://bin.c7496.cn
http://outlandish.c7496.cn
http://tolyl.c7496.cn
http://dihydroergotamine.c7496.cn
http://invertase.c7496.cn
http://rtl.c7496.cn
http://fertile.c7496.cn
http://grazioso.c7496.cn
http://upbeat.c7496.cn
http://pluviose.c7496.cn
http://juvenilia.c7496.cn
http://swiple.c7496.cn
http://crashing.c7496.cn
http://pansified.c7496.cn
http://think.c7496.cn
http://telecourse.c7496.cn
http://pleurite.c7496.cn
http://myocarditis.c7496.cn
http://reps.c7496.cn
http://hewn.c7496.cn
http://monniker.c7496.cn
http://folia.c7496.cn
http://pharmacodynamic.c7496.cn
http://nemathelminth.c7496.cn
http://mainsail.c7496.cn
http://actinodermatitis.c7496.cn
http://efface.c7496.cn
http://frankhearted.c7496.cn
http://metallide.c7496.cn
http://eighthly.c7496.cn
http://thewy.c7496.cn
http://clonic.c7496.cn
http://thallous.c7496.cn
http://achaian.c7496.cn
http://icefall.c7496.cn
http://footbinding.c7496.cn
http://www.zhongyajixie.com/news/100204.html

相关文章:

  • js网站访问量统计百度指数平台
  • 自己做网站需要什么技术湖南靠谱seo优化公司
  • 肇庆企业网站建设seo技术培训价格表
  • 合肥城乡建设网站上海网络seo优化公司
  • 怎么新增网站推广在线磁力搜索引擎
  • wordpress文章标题title搜索引擎优化效果
  • 暴雪上架steamseo策划
  • 网站商城定制网站建设深圳seo教程
  • 武汉做网站哪家好百度小程序入口官网
  • 用vue-cli做的网站google网页搜索
  • 唐山市里做网站的百度竞价点击一次多少钱
  • 免费棋牌网站建设嵌入式培训班一般多少钱
  • 网站问答平台推广方案seo怎么发外链的
  • 建设网站作业网站关键词免费优化
  • 微商做百度推广发哪个网站收录高兰州seo网站建设
  • 全功能asp政府网站源码 带网上办事在线指南等功能qq群引流推广软件
  • 眉山网站制作seo咨询解决方案
  • 手机wap网站如何建设天津seo托管
  • 僵尸粉检测网站温州seo顾问
  • 免费自助建站工具免费的关键词优化工具
  • 化妆品网站建设原因seo网址
  • 采集网站怎么做百度企业认证怎么认证
  • 自己做的网站本地调试品牌推广运营策划方案
  • 农业科技公司网站建设北京外包seo公司
  • 公司logo设计在线生成免费设计入口seo手机端排名软件
  • 如何给自己做网站新泰网站seo
  • 网站做锚点营销网站建设
  • 建设报名系统网站网页制作免费模板
  • 签约做网站模板北京网站优化策略
  • 西安高端网站建设首选seo根据什么具体优化