Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1221
Description
A software company is planning an n-day software development program, according to the development plan I need NI software developers, in order to improve the efficiency of software developers, the company provides software personnel with a lot of services, one of the services is to provide each developer a daily disinfection towel, This disinfectant towel must be sterilized after one day to be used. Disinfection methods There are two, a mode of disinfection needs a day, B mode of disinfection needs B Day (B>a), a disinfection method of the cost of each towel FA, B disinfection method of the cost of each towel fb, and buy a new towel for the cost of f (new towel is disinfected, the day can be used); >FA>FB. The company's manager is planning how many new towels to buy each day, how many towels per day, and how many towels are sent per day for the B disinfection of these n days. Of course, company managers want the lowest cost. Your job is to plan how many towels to buy per day, how many towels per day, and how many towels to disinfect for B, so that the company has the lowest total cost of providing towel service in this N-day software development.
Input
1th Act N,A,B,F,FA,FB. 2nd Act N1,n2,......,nn. (Note: 1≤f,fa,fb≤60,1≤n≤1000)
Output
Minimum cost
Build diagram:
Create additional source and sink points s and T
1. The source point to the first day of the in point of the capacity ni cost of 0 side
2. The point of the first day to the meeting point with a capacity ni cost of 0 side
3. From the source point to the I-day out point with the capacity of the INF fee is the edge of f (guaranteed daily out point to the meeting point full stream)
4. The point of entry to the I+a+1 (i+b+1) Day of the first day of the order with the capacity of the INF cost for the side of the FA (FB) (on behalf of two disinfection methods)
5. The entry point to the i+1 day of the first day of the connection capacity for the INF cost of 0 of the edge (on behalf of the rest of the day towels can be saved to the next day)
Then run the cost stream
Yesterday, from the Tle learned the cost of the flow of multi-augmentation posture, a try to scare: Tan wide 3244ms, multi-channel augmentation 48ms
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <queue>6 #defineRep (i,l,r) for (int i=l; i<=r; i++)7 #defineCLR (x, y) memset (x,y,sizeof (×))8 #defineTravel (x) for (Edge *p=last[x]; p; p=p->pre)9 using namespacestd;Ten Const intINF =0x3f3f3f3f; One Const intMAXN =1010; AInlineintRead () { - intAns =0, F =1; - Charc =GetChar (); the for(;!isdigit (c); C =GetChar ()) - if(c = ='-') F =-1; - for(; IsDigit (c); C =GetChar ()) -Ans = ans *Ten+ C-'0'; + returnAns *F; - } + structedge{ AEdge *pre,*rev;intTo,cap,cost; at}edge[maxn* A],*last[maxn<<1],*cur[maxn<<1],*pt; - intn,a,b,f,fa,fb,x,s,t,cost,d[maxn<<1]; - BOOLisin[maxn<<1],vis[maxn<<1]; -Queue <int>Q; -InlinevoidAddintXintYintZintW) { -Pt->pre = Last[x]; Pt->to = y; Pt->cap = Z; Pt->cost = W; LAST[X] = pt++; inPt->pre = Last[y]; Pt->to = x; Pt->cap =0; Pt->cost =-W; Last[y] = pt++; -Last[x]->rev = Last[y]; Last[y]->rev =Last[x]; to } + BOOLSPFA () { -CLR (Isin,0); Isin[s] =1; Q.push (S); theCLR (D,inf); D[s] =0; * while(!Q.empty ()) { $ intnow = Q.front (); Q.pop (); Isin[now] =0;Panax Notoginseng Travel (now) { - if(D[p->to] > D[now] + p->cost && p->cap >0){ theD[p->to] = D[now] + p->Cost ; + if(!isin[p->to]) isin[p->to] =1, Q.push (p->to ); A } the } + } - returnD[T]! =INF; $ } $ intDfsintXintflow) { - if(x = = T | | (!flow))returnFlow VIS[X] =1;intW =0; - for(Edge *p = cur[x]; p && w < flow; p = p->pre) { the if(P->cap >0&& (!vis[p->to]) && d[p->to] = = D[x] + p->Cost ) { - intDelta = DFS (p->to,min (p->cap,flow-W));WuyiP->cap-= Delta; P->rev->cap + = Delta; W + =Delta; theCost + = P->cost *Delta; - if(p->cap) Cur[x] =p; Wu } - } About returnW; $ } - voidMincost () { - while(SPFA ()) { -CLR (Vis,0); ARep (i,s,t) cur[i] =Last[i]; + DFS (s,inf); the } - } $ intMain () { then = read (); A = read (); b = Read (); f = Read (); FA = Read (); FB =read (); theS =0; T = n <<1|1; theCLR (Last,0); PT =Edge; theRep (I,1, n) x = Read (), add (S,i,x,0), add (I+n,t,x,0); -Rep (I,1, n) Add (s,i+n,inf,f); inRep (I,1, N-1) Add (i,i+1Inf0); theRep (I,1, N) { the if(i + A +1<= N) Add (i,i+n+a+1, INF,FA); About if(i + B +1<= N) Add (i,i+n+b+1, INF,FB); the } the mincost (); theprintf"%d\n", cost); + return 0; -}View Code
BZOJ1221 [HNOI2001] software development