Welcome to the
original source-- Blog Park-zhouzhendong go to the blog Park to see the puzzleTopic Portal-BZOJ2809Test Instructions Summary
N points make up a tree, each point has a leadership and cost, you can make a point when the leader, and then in this point of the sub-tree select some cost and not more than M points, get leadership leadership by the number of points selected (leader can not be selected) profit. The maximum value of the profit. n≤100000
Solving
Do a tree-like DP operation.
Maintaining a large heap, each time from a child node to a parent node, is the heap that merges all the child nodes.
Use a left-leaning tree.
Then delete the big first until it is legal.
There seems to be nothing to say.
Code
#include <cstring> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cmath >using namespace Std;typedef long long ll;const int n=100005;struct gragh{int cnt,y[n],nxt[n],fst[n];void Clear () {CNT =0;memset (fst,0,sizeof fst);} void Add (int a,int b) {y[++cnt]=b,nxt[cnt]=fst[a],fst[a]=cnt;}} G;int n,m,l[n],fa[n],c[n],root[n],cnt[n];struct heap{int ls,rs,v,len;void Set (int a,int b,int c,int d) {ls=a,rs=b,v=c, Len=d;}} H[n]; LL Ans=0,tot[n]; ll Max (ll A,ll b) {return a>b?a:b;} int merge (int a,int b) {if (a==0| | b==0) return a+b;if (H[A].V<H[B].V) swap (A, b); H[a].rs=merge (h[a].rs,b); if (H[h[a].ls].len
BZOJ2809 [apio2012]dispatching can be stacked