题目大意:给定一棵 N 个点的树,边有边权,定义"线树"为一个图,其中图的顶点是原树中的边,原树中两条有公共端点的边对应在线图中存在一条边,边权为树中两条边的边权和,求线图的最小生成树的代价是多少. 题解: 对于树中的一个顶点来说,假设有 M 条边以该顶点为一个端点,那么这 M 条边对应到线图中的顶点必须要求能够构成一个联通块.另外,可以发现这个问题的解决和其他顶点无关,即:对于树上每个顶点来说,构成了一个子问题.因此,考虑一个贪心策略,即:每次用边权最小的那条边和其他所有边相连,这样…
题目大意:NOIP2018d1t1 支持 M 次区间查询答案和区间修改操作. 题解: 首先考虑不带区间修改的情况.从左到右进行考虑,发现对于第 i 个数来说,对答案的贡献仅仅取决于第 i-1 个数的大小:若 \(a_i \le a_{i-1}\),则第 i 个数对答案的贡献为 0,否则对答案的贡献为两者的差值.贡献可以这样算是因为每个点至少增加 \(a_i\) 次,且当前点增加多少仅对后面一个数有直接影响.因此,考虑维护差分数组即可,区间修改变成两次单点修改,区间查询转变成查询区间大于 0 的数…
题解: solution Code: A. Apple Business #include<cstdio> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int N=100010; int Case,len[N],n,m,i,mx,a[N],size[N],tmp[N];ll ans; vector<ll>v[N],f[N]; str…
B. Balanced Diet 思路:把每一块选C个产生的价值记录下来,然后从小到大枚举C. #include<bits/stdc++.h> using namespace std; ; typedef long long ll; vector<int> G[maxn]; int l[maxn], a[maxn], b[maxn]; ll dp[maxn]; bool cmp(int a, int b) { return a > b; } int main() { std:…
ZOJ Problem Set - 3946 Highway Project Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus…
The Lucky Week Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date. There was one day Edward suddenly found that if Monday was the 1st, 11th or 21st day…
People Counting Time Limit: 2 Seconds      Memory Limit: 65536 KB In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone w…
Defuse the Bomb Time Limit: 2 Seconds      Memory Limit: 65536 KB The bomb is about to explode! Please defuse it as soon as possible! There is a display showing a number from 1 to 4 on the bomb. Besides this, there are 4 buttons under the display. Ea…
提交链接 http://codeforces.com/gym/100781/submit Description: Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fights they have finally decided to buy a video tape recorder. This fabulous, new device can reco…
当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数组用来优化,状态转移方程:dp[i][j]=sum(dp[i-1][k])----k需要满足a[j]>a[k]&&k<j; i表示所要选的个数,j表示以第a[j]个数结尾所有的符合要求的递增串的个数,最后答案就是sum(dp[n][j])--1<=j<=p;n 为要选的…