HDU 3572 Task Schedule Max stream dinic algorithm, card time: The building is very fastidious

Source: Internet
Author: User

Task ScheduleTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4617 Accepted Submission (s): 1513


Problem Descriptionour Geometry Princess XMM has stoped she study in computational geometry to concentrate on her newly op Ened Factory. Her factory had introduced M new machines in order to process the coming N tasks. For the i-th task, the factory have to start processing it on or after day Si, process it for Pi days, and finish the task Before or at day Ei. A machine can have work on one task at a time, and each task can be processed by at a time. However, a task can is interrupted and processed on different machines on different days.
Now she wonders whether he had a feasible schedule to finish all the tasks in time. She turns to the help.

Inputon The first line comes an integer T (t<=20), indicating the number of test cases.

You are given-N (n<=500) and M (m<=200) on the first line of all test case. Then on each of next N lines is three integers Pi, si and Ei (1<=pi, Si, ei<=500), which has the meaning described In the description. It is guaranteed, this in a feasible schedule every task, can be finished would be do 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
maximum flow. The construction of this problem is classic, because the limit of each time each machine can only handle a task, so you can assign time points to the various legitimate machines ... The specific is to set a super source point s, connected to each task, capacity for the task time, the task is connected to the point in the range of time, the capacity of 1 (guaranteed every moment xxx this condition), all time points to the Super meeting point T, the capacity of the machine number, and finally the maximum flow, is equal to all machines and the time required is YesCode:
#include <cstdio> #include <cstring> #include <queue> #define SIZE 1100#define INF 1000000000using namespace std; struct edge{int to, W, next;} Edge[size*size];int N, M, start, ends, index = 0;int head[size], level[size], Cur[size];bool visited[size]; BOOL BF S () {queue<int> que; Que.push (start), memset (level), level,-1,sizeof] = 0; while (Level[start ()) {int  pos = Que.front (); Que.pop (); for (int next = Head[pos]; next = 1; next = Edge[next].next) {if (level[edge[next].to]<0 && edge[next].w>0) {level[edge[next].to] = level[pos]+1; Que.push (edge[next].to);}} return Level[ends]! =-1;} int min (int a, int b) {return a>b?b:a;} int dfs (int pos, int flow) {int deta = 0, tmp = 0;if (pos = = ends) return flow; for (int next = Head[pos]; next! = 1; NEX t = edge[next].next) {if (edge[next].w > 0 && level[pos] = = level[edge[next].to]-1) {tmp = DFS (edge[next].to,min (FLOW-DETA,EDGE[NEXT].W)) ; if (tmp>0) {EDGE[NEXT].W = tmp; edge[next^1].W + = tmp;d eta + = tmp; if (deta = = flow) break;} Elselevel[edge[next].to] =-1;//Do not add this, timeout ... }}return Deta;} int dinic () {int ans = 0, flow = 0, while (BFS ()) {int deta = 0; ans + = DFS (0,inf);} return ans;} void Add (int s, int d, int w) {edge[index].next = Head[s]; edge[index].to = D; edge[index].w = w; head[s] = index + +; EDG E[index].next = Head[d]; edge[index].to = s; edge[index].w = 0; Head[d] = index + +;} int main () {int T, c = 1; scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m); Memset (Head,-1,sizeof (head)); index = 0; int sum = 0, max = -1;start = 0;for (int i = 1; I <= n; ++i) {int x, y, Z; scanf ("%d%d%d", &x,&y,& AMP;Z); sum + = x; max = max>z?max:z; add (start,i,x); for (int j = y; J <= Z; ++j) {Add (i,j+n,1);}} ends = n+max+1; for (int i = 1; I <= max; ++i) Add (i+n,ends,m), int ans = dinic ();p rintf ("Case%d:", C + +); if (ans! = s UM) puts ("no\n"); Elseputs ("yes\n");} return 0;}

with June

HDU 3572 Task Schedule Max stream dinic algorithm, card time: The building is very fastidious

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.