luogu2577/bzoj1899 Lunch (greedy +dp)

Source: Internet
Author: User

First of all, should try to let the food slow row in front, first by this row order

and decide which way everyone is going.

Set F[i][j] is done with the first person, then the 1th window currently has a total queue time of J, the current maximum total time

With this I and J words, and then preprocess the former I personal queue total time sum[i], you can know that the queue time in window 2nd is sum[i]-j

Just take two to update the answer.

1#include <bits/stdc++.h>2 #definePA pair<int,int>3 #defineCLR (a,x) memset (A,x,sizeof (a))4 using namespacestd;5typedefLong Longll;6 Const intmaxn= About;7 8 Inline LL Rd () {9ll x=0;CharC=getchar ();intneg=1;Ten      while(c<'0'|| C>'9'){if(c=='-') neg=-1; c=GetChar ();} One      while(c>='0'&&c<='9') x=x*Ten+c-'0', c=GetChar (); A     returnx*neg; - } -  the intf[maxn][maxn*MAXN],ST[MAXN]; - intN; - structnode{ -     inte,q; + }P[MAXN]; -  +InlineBOOLCMP (Node A,node b) {returnA.e>B.E;} A  at intMain () { -     //freopen ("", "R", stdin); -     inti,j,k; -n=Rd (); -      for(i=1; i<=n;i++){ -P[i].q=rd (), p[i].e=Rd (); in}sort (p+1, p+n+1, CMP); -      for(i=1; i<=n;i++) tost[i]=st[i-1]+p[i].q; +      -CLR (F,127); f[0][0]=0; the      for(i=1; i<=n;i++){ *          for(j=0; j<=n* $; j + +){ $             if(f[i-1][J]&GT;=1E8)Continue;Panax NotoginsengF[i][j+p[i].q]=min (F[i][j+p[i].q],max (f[i-1][j],j+p[i].q+p[i].e)); -F[i][j]=min (F[i][j],max (f[i-1][j],st[i]-j+p[i].e)); the         } +     } A     intans=1e9; the      for(j=0; j<=n* $; j + +) +ans=min (ans,f[n][j]); -printf"%d\n", ans); $     return 0; $}

luogu2577/bzoj1899 Lunch (greedy +dp)

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.