[bzoj2131] Free Pies _ tree-like array

Source: Internet
Author: User

Free Pies bzoj-2131

Main Topic :

Note : $1\le n \le 10^5$,$1\le w \le 10^8$.

idea : First, think of DP

status : Dp[i][j] represents the maximum benefit of I minute in position J

Optimized optimization

status : Dp[i] Indicates the maximum benefit of the last received I.

Transfer : Order enumeration i:1->n.

then , we try to optimize

For this state we will find that there is an absolute dead thing at the time of transfer, and we take it apart:

2*t[j]+pos[j]<=2*t[i]+pos[i] and 2*t[j]-pos[j]<=2*t[i]-pos[i]

Then, by subtracting the subscript, the addition is updated on the tree-shaped array.

finally , attach the ugly code ...

 #include <iostream> #include <cstdio> #include <cstring># Include <algorithm>using namespace Std;int w,n,f[100010],hash[100010],cnt,ans,s[100010];struct pies{int t,p,v, W1,W2;} A[100010];int CMP (const pies &a,const pies &b) {return a.w1<b.w1;} int lowbit (int x) {return x& (-X);} int ask (int i) {int max=0;while (i!=0) {Max=max (max,s[i]); I-=lowbit (i);} return Max;} void Add (int i,int val) {while (i<=cnt) {S[i]=max (s[i],val); i+=lowbit (i);}} int main () {scanf ("%d%d", &w,&n), for (int i=1;i<=n;i++) {scanf ("%d%d%d", &a[i].t,&a[i].p,&a[i] . v); a[i].t*=2;a[i].w1=a[i].t-a[i].p;a[i].w2=a[i].t+a[i].p;hash[++cnt]=a[i].w2;} Sort (hash+1,hash+cnt+1); Cnt=unique (hash+1,hash+cnt+1)-hash-1;for (int i=1;i<=n;i++) {A[i].w2=lower_bound (hash+ 1,HASH+CNT+1,A[I].W2)-hash;} Sort (a+1,a+n+1,cmp), for (int i=1;i<=n;i++) {f[i]=ask (A[I].W2) +a[i].v;ans=max (Ans,f[i]), add (A[i].w2,f[i]);} printf ("%d\n", ans); return 0;} 

Summary : None.

[bzoj2131] Free Pies _ tree-like array

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.