There is a software company that needs to provide some staff with disinfection towels every day, these towels can be recycled, but they need to be disinfected. Towels can be sent to disinfect, there are two ways, a-day FA cost, B-day FB cost. Or you can buy a new towel directly and ask for at least how much it will cost to meet the needs of your staff.
Idea: Classic cost-flow issues. Each day will be split, s to <<1 each day, to constrain how many towels are needed each day; <<1|1 to the T-edge every day to constrain the towels needed every day. Every day <<1 to the day the towel can be used to clean the day <<1|1, note A and B. Towel can be postponed use, then every day <<1|1 to (+1 per day) <<1|1, indicating that the use of delay. Then run EK.
CODE:
#include <queue> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define MAX 2010#define maxe 100000#define INF 0x3f3f3f3f#define S 0#define T (MAX-1) using namespace std; #d Efine Max (a) > (b)? (a):(B)) struct mincostmaxflow{int head[max],total; int Next[maxe],aim[maxe],flow[maxe],cost[maxe]; int From[max],p[max],f[max]; BOOL V[max]; Mincostmaxflow (): Total (1) {} void Add (int x,int y,int f,int c) {next[++total] = head[x]; Aim[total] = y; Flow[total] = f; Cost[total] = c; HEAD[X] = total; } void Insert (int x,int y,int f,int c) {Add (x,y,f,c); ADD (Y,X,0,-C); } bool Spfa () {static queue<int> q; memset (F,0x3f,sizeof (f)); memset (v,false,sizeof (v)); while (!q.empty ()) Q.pop (); Q.push (S); F[s] = 0; while (!q.empty ()) {int x = Q.front (); Q.pop (); V[X] = FalsE for (int i = head[x]; i; i = Next[i]) if (Flow[i] && f[aim[i]] > F[x] + cost[i]) { F[aim[i]] = f[x] + cost[i]; if (!v[aim[i]]) {V[aim[i]] = true; Q.push (Aim[i]); } From[aim[i]] = x; P[aim[i]] = i; }} return f[t]! = INF; } int Edmondskarp () {int re = 0; while (SPFA ()) {int max_flow = INF; for (int i = T; i = S; i = from[i]) max_flow = min (max_flow,flow[p[i]]); for (int i = T; i = S; i = From[i]) {Flow[p[i]]-= Max_flow; FLOW[P[I]^1] + = Max_flow; } Re + = f[t] * max_flow; } return re; }}solver; int days,buy_cost,slow,slow_cost,fast,fast_cost; int main () {cin >> days >> slow >> fast >> buy_cost >> slow_cost >> Fast_cost; ++slow,++fast; for (int x,i = 1; I <= days; ++i) {scanf ("%d", &x); Solver.insert (s,i << 1,x,0); Solver.insert (i << 1|1,t,x,0); Solver.insert (s,i << 1|1,inf,buy_cost); } for (int i = 1; I <= days; ++i) {if (i + slow <= days) Solver.insert (i << 1, (i + slow) << 1|1 , inf,slow_cost); if (i + fast <= days) Solver.insert (i << 1, (i + fast) << 1|1,inf,fast_cost); } for (int i = 1; i < days; ++i) Solver.insert (i << 1|1, (i + 1) << 1|1,inf,0); cout << solver.edmondskarp () << Endl; return 0;}
Bzoj 1221 Hnoi 2001 software Development/Network Flow 24 question Napkin Plan problem minimum cost maximum flow