1#include <cstdio>2#include <iostream>3#include <cstring>4 #defineM 100015 #defineINF 21390621436 using namespacestd;7 intCnt=1, sum,t,n,a,b,f1,fa,fb,a1[m],d[m],fr[m],f[m],q[2*m],head[m],fro[ -*m],next[ -*m],u[ -*m],v[ -*m],w[ -*M];8 intans;9 voidJia1 (intA1,intA2,intA3,intA4)Ten { Onecnt++; Anext[cnt]=HEAD[A1]; -head[a1]=CNT; -fro[cnt]=A1; theu[cnt]=A2; -v[cnt]=A3; -w[cnt]=A4; - } + BOOLSPFA () - { +memset (D,127,sizeof(int) * (t+1)); Ad[0]=0; atf[0]=1; -q[1]=0; - intH=0, t=1; - for(;h<t;) - { -h++; in intp=Q[h]; -f[p]=0; to for(intI=head[p];i;i=Next[i]) + if(v[i]&&d[u[i]]>d[p]+W[i]) - { thed[u[i]]=d[p]+W[i]; *fr[u[i]]=i; $ if(!F[u[i]])Panax Notoginseng { -f[u[i]]=1; thet++; +q[t]=U[i]; A } the } + } - if(d[t]!=inf) $ return 1; $ return 0; - } - voidMCF () the { - intmx=inf;Wuyi for(intI=fr[t];i;i=Fr[fro[i]]) themx=min (mx,v[i]); - for(intI=fr[t];i;i=Fr[fro[i]]) Wu { -v[i]-=MX; Aboutv[i^1]+=MX; $ans+=mx*W[i]; - } - return; - } A voidJiaintA1,intA2,intA3,intA4) + { the jia1 (A1,A2,A3,A4); -Jia1 (A2,A1,0,-A4); $ return; the } the intMain () the { thescanf"%d%d%d%d%d%d",&n,&a,&b,&f1,&fa,&FB); - for(intI=1; i<=n;i++) inscanf"%d",&a1[i]); thet=2*n+1; the for(intI=1; i<=n;i++) About { the if(i<N) theJia (i,i+1Inf0); theJia0, I,a1[i],0); +Jia0, i+n,inf,f1); -Jia (I+n,t,a1[i),0); the intb1=i+a+1;Bayi if(b1<=N) theJia (i,n+B1,INF,FA); theb1=i+b+1; - if(b1<=N) -Jia (i,n+B1,INF,FB); the } the for(; SPFA ();) the MCF (); theprintf"%d\n", ans); - return 0; the}
For each day, a split s to i1 with a capacity of NI, an edge of 0, S to i2 with a capacity of INF, an edge of F, i2 to a T with a capacity of NI, a cost of 0 for the edge, I1 to (i+1) a capacity of INF, a cost of 0 edge.
I1 to (I+A) 2 The capacity for the INF, the cost for the side of the FA, the I1 to (I+B) 2 The capacity for the INF, the cost for the side of the FB.
Bzoj 1221: [HNOI2001] Software development