BZOJ1221[HNOI2001] Software Development

Source: Internet
Author: User

BZOJ1221[HNOI2001] Software Development

Test instructions

N days, the daily need to disinfect the AI bar towel, this disinfectant towel used after a day must be disinfected before use. Disinfection methods There are two, a mode of disinfection needs a day, a cost fa,b way of disinfection needs B days, a cost FB, buy a new towel for the cost of f (new towel is disinfected, the same day can be used), to find the minimum cost. n≤1000

Exercises

Cost flow. Split every day into X and Y. s to all X-linked side of the towel, all y to the T-side of the towel, the flow of the need to towel 0. Xi to the Yi+a, said a way disinfection, Xi to yi+b with the edge, said the B mode disinfection, s to all Y side, to buy a new, Xi to xi+1 with the edge, that the day before useless to get the next days use. Reflection: The key to cost flow is to seize the "traffic first".

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 30007 #defineINF 0X3FFFFFFF8 using namespacestd;9 Ten structe{intF,t,c,w,n;}; E es[maxn* +];intESS,G[MAXN]; OneInlinevoidPeintFintTintCintW) { AEs[++ess]= (e) {f,t,c,w,g[f]}; g[f]=ess; Es[++ess]= (e) {t,f,0,-w,g[t]}; g[t]=ess; - } - voidInit () {ess=-1; memset (g,-1,sizeof(g));} the intD[MAXN],FR[MAXN];BOOLINQ[MAXN]; Queue <int>Q; - BOOLSPFA (intSintt) { -      while(!q.empty ()) Q.pop (); memset (INQ,0,sizeof(INQ)); memset (d,-1,sizeof(d)); -inq[s]=1; d[s]=0; Q.push (s); fr[s]=-1; +      while(!Q.empty ()) { -         intX=q.front (); Q.pop (); inq[x]=0; +          for(inti=g[x];i!=-1; i=es[i].n)if(es[i].c&& (d[es[i].t]==-1|| d[es[i].t]>d[x]+ES[I].W)) { AD[ES[I].T]=D[X]+ES[I].W; Fr[es[i].t]=i;if(!inq[es[i].t]) inq[es[i].t]=1, Q.push (es[i].t); at         } -     } -     returnd[t]!=-1; - } - intAdvancedintSintt) { -     intA=inf,c=0; in      for(inti=fr[t];i!=-1; I=FR[ES[I].F]) a=min (a,es[i].c); -      for(inti=fr[t];i!=-1; I=FR[ES[I].F]) es[i].c-=a,es[i^1].c+=a,c+= (A *ES[I].W); to     returnC; + } - intMaxflowmincost (intSintt) { the     intC=0; while(SPFA (s,t)) c+=advanced (s,t);returnC; * } $ intn,a,b,f,fa,fb,s,t,x;Panax Notoginseng intMain () { -scanf"%d%d%d%d%d%d", &AMP;N,&AMP;A,&AMP;B,&AMP;F,&AMP;FA,&AMP;FB); s=0; t=2*n+1; init (); theInc (I,1, N) scanf ("%d", &x), PE (S,I,X,0), PE (N+I,T,X,0); +Inc (I,1, N) { A         if(i+a<n) PE (i,n+i+a+1, INF,FA);if(i+b<n) PE (i,n+i+b+1, INF,FB); the         if(i<n) PE (i,i+1Inf0); PE (s,i+n,inf,f); +     } -printf"%d", Maxflowmincost (s,t));return 0; $}

20160602

BZOJ1221[HNOI2001] Software Development

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.