BZOJ2809 [apio2012]dispatching can be stacked

Source: Internet
Author: User

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&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.