Hdu 3572 Task Schedule (network stream dinic algorithm)
Task Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 3412 Accepted Submission (s): 1197
Problem DescriptionOur geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. her factory has introduced M new machines in order to process the coming N tasks. for the I-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. however, a task can be interrupted and processed on different machines on different days.
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
InputOn the first line comes an integer T (T <= 20), indicating the number of test cases.
You are given two integer N (N <= 500) and M (M <= 200) on the first line of each test case. then on each of next N lines are three integers Pi, Si and Ei (1 <= Pi, Si, Ei <= 500), which have the meaning described in the description. it is guaranteed that in a feasible schedule every task that can be finished will be done before or at its end day.
OutputFor each test case, print "Case x:" first, where x is the case number. if there exists a feasible schedule to finish all the tasks, print "Yes", otherwise print "No ".
Print a blank line after each test case.
Sample Input
24 31 3 5 1 1 42 3 73 5 92 22 1 31 2 2
Sample Output
Case 1: Yes Case 2: Yes
Authorallenlowesy
Idea: create a super source point 0, then assume that the length of the work interval is T, and then create [1, T] points, the traffic from the source point to each point is M (only M machines work every day), and then shift the corresponding working day back to T day, every working day to the corresponding [1, t] The traffic is 1, and the traffic to the end is also 1.
Finally, check whether the maximum flow is greater than or equal to the total workload.
# Include "stdio. h" # include "string. h" # include "queue" using namespace std; # define N 1005 # define max (a, B) (a> B? A: B) # define min (a, B) (
0) {map [I]. w-= tmp; map [I ^ 1]. w + = tmp; cost + = tmp; if (cost = lim) break;} else dis [v] =-1 ;}} return cost;} int dinic () {int ans = 0, s = 0; while (bfs () ans + = dfs (s, inf); // printf ("% d \ n", ans ); return ans;} int main () {int I, j, T, sum, t1, t2, cas = 1; int s [505], e [505], p [505]; scanf ("% d", & T); while (T --) {scanf ("% d", & n, & m ); t1 = N; t2 = 0; sum = 0; for (I = 1; I <= n; I ++) {scanf ("% d ", & p [I], & s [I], & e [I]); t1 = min (t1, s [I]); t2 = max (t2, e [I]); sum + = p [I];} cnt = 0; memset (head,-1, sizeof (head); for (I = t1; I <= t2; I ++) // traffic from the Super source to the general source {add (0, I, m) ;}for (I = 1; I <= n; I ++) {for (j = s [I]; j <= e [I]; j ++) {add (j, j + t2, 1 ); add (j + t2, 2 * t2, 1) ;}} t = t2 * 2; if (sum <= dinic () printf ("Case % d: yes \ n ", cas ++); else printf (" Case % d: No \ n ", cas ++);} return 0 ;}