Bare cost stream ....
Map method: Abstract each month into a single point
s to each point of the edge, the cost of the purchase price of the month, the capacity of unlimited; each point to the T-edge, the cost is 0, the capacity of the current month sell volume
One-month point-to-point edge, cost for warehouse storage m, capacity for warehouse capacity s
1 /**************************************************************2 problem:24243 User:rausen4 language:c++5 result:accepted6 time:0 Ms7 memory:1028 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <algorithm> A - using namespacestd; - Const intINF = (int) 1e9; the Const intN =2005; - Const intM =10005; - structedges{ - intnext, to, cost, F; + } E[m]; - inttot =1, N, M, s; + intFirst[n], d[n], g[n], q[m]; A BOOLV[n]; at intS, T, ans; - -InlineintRead () { - intx =0, SGN =1; - CharCH =GetChar (); - while(Ch <'0'|| CH >'9'){ in if(ch = ='-') SGN =-1; -CH =GetChar (); to } + while(Ch >='0'&& CH <='9'){ -x = x *Ten+ CH-'0'; theCH =GetChar (); * } $ returnSGN *x;Panax Notoginseng } - theInlinevoidAdd_edge (intXintYintDintc) { +E[++tot].next =First[x]; AFIRST[X] =tot; theE[tot].to =y; +E[TOT].F =D; -E[tot].cost =C; $ } $ - voidAdd_edges (intXintYintDintc) { - Add_edge (x, Y, D, c); theAdd_edge (y, X,0, -c); - }Wuyi theInlineintCalc () { - intFlow =inf; Wu for(intx = G[t]; X x = g[e[x ^1].to]) -Flow =min (flow, e[x].f); About for(intx = G[t]; X x = g[e[x ^1].to]) $E[X].F-= flow, e[x ^1].F + =flow; - returnflow; - } - A BOOLSPFA () { + for(inti =1; I <= T; ++i) theD[i] =inf; -D[s] =0, v[s] =1; $q[1] =S; the intx, y; the for(intL =1, r =1; L <= R; ++l) { the for(x = first[q[l]]; x; x =E[x].next) { they =e[x].to; - if(D[q[l]] + e[x].cost < D[y] &&e[x].f) { inD[y] = D[q[l]] +E[x].cost; theG[y] =x; the if(!V[y]) AboutQ[++r] = y, v[y] =1; the } the } theV[q[l]] =0; + } - returnD[T]! =inf; the }Bayi the intMain () { then = Read (), M = Read (), s =read (); -S = n +1, T = n +2; - for(inti =1; I <= N; ++i) theAdd_edges (i, T, read (),0); the for(inti =1; I <= N; ++i) the add_edges (S, I, INF, read ()); the for(inti =1; I < n; ++i) -Add_edges (i, i +1, S, m); the while(SPFA ()) theAns + = Calc () *D[t]; theprintf"%d\n", ans);94 return 0; the}View Code
BZOJ2424 [HAOI2010] Order