Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=3572
Main topic:
Give n a task, M machine. Each task has the earliest time to start doing s,deadline E, and the duration of the work is P. Each task can be segmented, but at the same time, a single machine can perform at most one task. There is no viable working time to ask for a deposit.
Problem Solving Ideas:
Since time <=500 and each task can be executed intermittently, we use the network stream as a node to solve the problem.
Map: Source point S (number 0), time 1-500 days numbered 1 to ten, N tasks numbered 500+1 to 500+n, meeting point T (numbered 501+n).
Source point s to each task I have side (s, I, Pi)
Every day to the meeting point there is an edge (J, T, M) (in fact, every day here is not necessarily from 1 to 500, just take those that are covered by each task each day)
If task I can be performed on day J, then there is an edge (I, J, 1) note that because a task is executed at most 1 machines in a day, the edge capacity is 1 and cannot be inf or M oh.
Finally, see if the maximum flow is = = Total number of days required for all tasks.
The maximum flow of the augmented path will time out, and the augmented path should be optimized with the dinic algorithm.
(The topic of graph theory is difficult to figure out how to build, not the use of algorithms)
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 Const intMAXN = ++Ten;5 Const intINF =1e9;6 structEdge7 {8 intu, V, C, F;9 Edge () {}TenEdgeintUintVintCintf): U (U), V (v), C (c), F (f) {} One }; AVector<edge>e; -vector<int>G[MAXN]; - intLEVEL[MAXN];//BFS tiering the intITER[MAXN];//Current ARC Optimization - intN, M; - voidInit () - { + for(inti =0; i < MAXN; i++) g[i].clear (); - e.clear (); + } A voidAddedge (intUintVintc) at { -E.push_back (Edge (U, V, C,0)); -E.push_back (Edge (V, U,0,0)); - intm =e.size (); -G[u].push_back (M-2); -G[v].push_back (M-1); in } - voidBFS (ints) to { +Memset (Level,-1,sizeof(level)); -queue<int>Q; theLevel[s] =0; * Q.push (s); $ while(!q.empty ())Panax Notoginseng { - intU =Q.front (); the Q.pop (); + for(inti =0; I < g[u].size (); i++) A { theedge& now =E[g[u][i]]; + intv =now.v; - if(Now.c > Now.f && level[v] <0) $ { $LEVEL[V] = Level[u] +1; - Q.push (v); - } the } - }Wuyi } the intDfsintUintTintF//U is the current point, T is the end, and F is the current flow - { Wu if(U = = t)returnF; - for(int& i = Iter[u]; I < g[u].size (); i++)//Current ARC Optimization About { $edge& now =E[g[u][i]]; - intv =now.v; - if(Now.c > Now.f && level[u] <Level[v]) - { A intD = Dfs (V, t, Min (F, now.c-now.f)); + if(D >0) the { -NOW.F + =D; $E[g[u][i] ^1].F-=D; the returnD; the } the } the } - return 0; in } the intMaxflow (intSintt) the { About intFlow =0; the for(;;) the { the BFS (s); + if(Level[t] <0)returnflow; -memset (ITER,0,sizeof(ITER)); the intF;Bayi while(f = DFS (S, T, INF)) >0) Flow + =F; the } the returnflow; - } - intMain () the { the intT, cases =0; thescanf"%d", &T); the while(t--) - { thescanf"%d%d", &n, &m); the intMaxday =0; the intSumday =0;94 init (); the intp, S, E; the for(inti =1; I <= N; i++) the {98scanf"%d%d%d", &p, &s, &e); AboutAddedge (0, -+I, p); - for(intj = S; J <= E; J + +)101Addedge (i + -J1);102Maxday =Max (Maxday, e);103Sumday + =p;104 } the for(inti =1; I <= maxday; i++)106Addedge (I,501+N, m);107 if(Maxflow (0,501+ N) = =sumday)108printf"Case %d:yes\n\n", ++cases);109 Elseprintf"Case %d:no\n\n", ++cases); the }111 return 0; the}
hdu-3572 Task Schedule---Maximum flow estimation +dinic algorithm