HDU 5735 - Born Slippy】的更多相关文章

Born Slippy 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5735 Description Professor Zhang has a rooted tree, whose vertices are conveniently labeled by 1,2,...,n. And the i-th vertex is assigned with weight wi. For each s∈{1,2,...,n}, Professor Zh…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5735 [题目大意] 给出一棵树,树上每个节点都有一个权值w,w不超过216,树的根为1,从一个点往根的方向走,可以得到他的祖先序列,现在需要从v1点的祖先序列中挑选出一定数量的点,组成数列v1,v2,v3……vm,要求vi是vi-1的祖先,求dp[v1]=max(dp[vi]+(w[v1] opt w[vi])),opt是一种运算,在题目中可为xor,or或者and,最后求出ans=sum_{i…
题意: 一棵 n 个节点的根树,i 节点权重 wi 对每一个节点s,找到这样一个长 m 的标号序列 v : 1. vi是vi-1 的祖先 2. f[s] = w[vi] + ∑(i=2, m) (w[vi] opt w[vi-1]) 最大 要求输出:S = ∑(i=1, n) (i * f[i])  (mod 1e9 + 7) opt给出,为 & , ^ , | 的任意一种 数据范围: 2<= n <= 2^16 , 2 <= wi <= 2^16 分析: 普通转移方程:…
考虑DP,设$f[x]$表示最后一个是$x$时的最优解,则$f[x]=\max(f[y]+w[x]\ opt\ w[y])$,其中$y$是$x$的祖先. 注意到$w[i]<2^{16}$,那么将数字划分成前$8$位和后$8$位,额外维护一个数组$g[a][b]$表示某个$w[y]$的前$8$位为$a$时,后$8$位$opt\ b+f[y]$的最大值,那么维护$g$只需要枚举$b$,计算$f$只需要枚举$a$,单次复杂度都是$O(2^8)$. 对于树的情况只需要保存每次修改,然后在回溯的时候还原即…
首先是需要我们知道的是假设又一条链给你让你求最大值,你会求吗?当然会,就是时间有点爆炸O(n2).那不行,要是如果我把到达每个点的最大值以及他对后面的贡献情况都求出来后放在数组里面,然后到了新的节点直接查询该点的情况,但是问题就在于我们存进数组的时候遍历了O(1 << 16)那么时间还是不可以过,这时候需要使用大背包的想法,我们只把后面8为的结果打出来并存进数组,然后查询的时候只需要查询前8位,这样一来是不是时间就又优化到了允许的范围内了.还有就是我在树上面跑的时候会有重复的状况,就是两条链共…
8/13 2016 Multi-University Training Contest 2官方题解 数学 A Acperience(CYD)题意: 给定一个向量,求他减去一个  α(>=0)乘以一个值为任意+1或-1的B向量后得到向量,求这个向量膜的最小值思路: 展开式子,当时最小,结果为. 代码: #include <bits/stdc++.h> using namespace std; long long w,a,b,c,a2; long long gcd(long long x,l…
Acperience 展开式子, \(\left\| W-\alpha B \right\|^2=\displaystyle\alpha^2\sum_{i=1}^{n}b_i^2-2\alpha\sum_{i=1}^n{w_ib_i}+\sum_{i=1}^{n}w_i^2\). 由于\(b_i\in \{+1,-1\}\), 那么\(\displaystyle\sum_{i=1}^{n}b_i^2=n\), 显然\(c=\displaystyle\sum_{i=1}^{n}w_i^2\)也是常…
http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Problem Description   When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its bod…
Lucky7 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its body an…
主题链接:pid=2454">http://acm.hdu.edu.cn/showproblem.php?pid=2454 Problem Description Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the bound…