Bzoj 2879 NOI2012 Food Festival

Source: Internet
Author: User

Links: http://www.lydsy.com/JudgeOnline/problem.php?id=2879

CZ City in order to welcome students all over the country, specially held a grand food festival. As a gourmet guest who likes early taste, little M is naturally reluctant to miss the feast. He soon tasted all the delicacies of the Gourmet festival. However, the desires of the early adopters are difficult to satisfy. Even though all the dishes were delicious and the cooks were quick to cook, little m still felt that there was no food on his table that had been placed on others ' tables as an intolerable thing. So small m began to study the problem of cooking order, that is, arrange a cooking order so that the students have the shortest waiting time. Small m found that the food festival has a total of n different kinds of dishes. Every time you order a meal, each student can choose one of the dishes. There are a total of M cooks to make these dishes. When all the students ordered the meal, the food production task was assigned to each chef. Then each chef will start cooking at the same time. Cooks will make them in the order they are requested and can only produce one person at a time. In addition, small m also found another interesting thing: Although the M chef will make all the n vegetables, but for the same dish, the different cooks ' production time may not be the same. He will dish with 1, 2, ..., n sequentially numbered, cooks with 1, 2, ..., m sequentially numbered, the time of the first chef of the J cooks to make the vegetables is ti,j. Little M thinks: the waiting time for each classmate is the total length of time for all cooks to start cooking, to their own portion of the finished dish. In other words, if a classmate ordered a dish that was made by a chef, his waiting time was the sum of the time the chef cooked the K-course. The total waiting time is the sum of the waiting time for all the students. Now, small m found all the students a la carte information: There are PI students ordered the first I vegetable products (i=1, 2, ..., n). What he wants to know is what the minimum total waiting time is.

Train of thought: Dynamic construction point, each time if can have augmentation road, on the new point.

1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 #defineN 2000057 inttot,go[3000005],first[200005],next[3000005],flow[3000005],cost[3000005];8 intop[3000005], from[n],edge[n],dis[n],vis[n],c[2*N];9 inta[505][505],n,m,p[n],ans,s,t,all;Ten intRead () { One     intt=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} -     returnt*F; the } - voidInsertintXintYintZintl) { -tot++;go[tot]=y;next[tot]=first[x];first[x]=tot;flow[tot]=z;cost[tot]=l; - } + voidAddintXintYintZintl) { -Insert (x,y,z,l); op[tot]=tot+1; Insert (Y,x,0,-L); op[tot]=tot-1; + } A BOOLSPFA () { at      for(intI=0; i<=t;i++) dis[i]=0x3f3f3f3f, vis[i]=0; -     intH=1, t=1;d is[s]=0; c[1]=S; -      while(h<=t) { -         intnow=c[h++]; -          for(intI=first[now];i;i=Next[i]) { -             intPur=Go[i]; in             if(flow[i]&&dis[pur]>dis[now]+Cost[i]) { -dis[pur]=dis[now]+Cost[i]; to                  from[pur]=Now ; +edge[pur]=i; -                 if(Vis[pur])Continue; thevis[pur]=1; *c[++t]=pur; $             }Panax Notoginseng         } -vis[now]=0; the     } +     returndis[t]!=0x3f3f3f3f; A } the voidUpdata () { +     intmn=0x7fffffff, x, y; -      for(intI=t;i!=s;i= from[i]) { $mn=std::min (Mn,flow[edge[i]); $         if( from[i]==R) { -x= (I-1)/all+1; -y= (i)%all+1; the         } -     }Wuyi      for(intI=t;i!=s;i= from[i]) { theans+=mn*Cost[edge[i]]; -flow[edge[i]]-=mn; Wuflow[op[edge[i]]]+=mn; -     } About      for(intI=1; i<=m;i++) $Add (X-1) *all+y,n*all+i,1, y*a[i][x]); - } - intMain () { -M=read (); n=read (); As=0; +      for(intI=1; i<=m;i++){ thep[i]=read (); -all+=P[i]; $     } thet=m+n*all+1; the      for(intI=1; i<=n*all;i++) theAdd (S,i,1,0); the      for(intI=1; i<=m;i++) -Add (I+n*all,t,p[i],0);  in      for(intI=1; i<=m;i++) the       for(intj=1; j<=n;j++) thea[i][j]=read (); About      for(intI=1; i<=n;i++) the       for(intj=1; j<=m;j++) theAdd (I-1) *all+1, N*all+j,1, A[j][i]); the      while(SPFA ()) Updata (); +printf"%d\n", ans);  -}

Bzoj 2879 NOI2012 Food Festival

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.