HDU 3572 Task Schedule (split + Max stream dinic)

Source: Internet
Author: User

Task Schedule

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 7753 Accepted Submission (s): 2381

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 Input24 31 3 5 1 1 42 3 73 5 9 2 22 1 31 2 2

Sample outputcase 1:yes Case 2:yes

Title Link: HDU 3572

The maximum flow of the split is judged whether the problem is full flow, how to split it? From the source point s to each task I a capacity of the side of P, indicating that each task starts with a P flow inflow, and then each task I to the point of time [s,e] a capacity of 1 side, indicating that a task can only be used on one machine, that is not both machine A and machine B processing, Then each point of time to the T with a capacity of M-side, indicating that a point in time can only have a maximum of M machines at work. In the end, you just have to judge whether the $n*p$ flow from S is all flowing into T.

Space complexity is about $ (500+500^2+500) *2$ Edge, $500+500$ Point, originally only the most spicy chicken FF want to low altitude card This problem, but was infinite tle teach a man, check the puzzle and membrane film dinic, found Dinic also easy to understand, The significance of layering is to reduce the unused search, because the augmentation must be from the minimum distance distance to the minimum distance, then those d[v]!=d[u]+1 points can be ignored

Code:

#include <stdio.h> #include <bits/stdc++.h>using namespace std; #define INF 0x3f3f3f3f#define CLR (arr,val) memset (arr,val,sizeof (arr)) #define LC (x) (x<<1) #define RC (x) ((x<<1) +1) #define MID (x, y) ((x+y) >>1) typedef pair<int,int> PII;TYPEDEF Long Long ll;const double Pi=acos ( -1.0); const int N=1010;const int M=251000+7;STR    UCT edge{int to,nxt; int cap;};    Edge E[m<<1];int head[n],tot,d[n];void Add (int s,int t,int cap) {e[tot].to=t;    E[tot].cap=cap;    E[tot].nxt=head[s];    head[s]=tot++;    E[tot].to=s;    E[tot].cap=0;    E[TOT].NXT=HEAD[T]; head[t]=tot++;}    void Init () {CLR (head,-1); tot=0;}    int BFS (int s,int t) {CLR (d,-1);    d[s]=0;    queue<int>q;    Q.push (s); while (!        Q.empty ()) {int Now=q.front ();        Q.pop ();            for (int i=head[now]; ~i; i=e[i].nxt) {int v=e[i].to;                if (d[v]==-1&&e[i].cap>0) {d[v]=d[now]+1;  if (v==t)                  return 1;            Q.push (v); }}} return d[t]!=-1;} int dfs (int s,int t,int f) {if (s==t| |!    f) return F;    int r=0;        for (int i=head[s]; ~i; i=e[i].nxt) {int v=e[i].to;            if (d[v]==d[s]+1&&e[i].cap) {int D=dfs (v,t,min (F,e[i].cap));                if (d>0) {e[i].cap-=d;                E[i^1].cap+=d;                R+=d;                F-=d;            if (!f) break;    }}} if (!r) D[s]=inf; return r;}    int dinic (int s,int t) {int r=0;    while (BFS (s,t)) R+=dfs (S,t,inf); return r;}    int main (void) {int tcase,p,s,e,i,j,n,m;    scanf ("%d", &tcase);        for (int q=1; q<=tcase; ++q) {init ();        scanf ("%d%d", &n,&m);        int s=0;        int tl=inf,tr=-inf;        int sump=0;           for (I=1; i<=n; ++i) {scanf ("%d%d%d", &p,&s,&e); Add (s,i,p);            Sump+=p;            if (S&LT;TL) tl=s;            if (E&GT;TR) tr=e;        for (j=s; j<=e; ++j) Add (i,n+j,1);        } int t=n+tr+1;        for (I=TL; i<=tr; ++i) Add (n+i,t,m); printf ("Case%d:%s\n\n", Q,dinic (s,t) ==sump? "    Yes ":" No "); } return 0;}

HDU 3572 Task Schedule (split + max stream dinic)

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.