Hdu 3572 Task Schedule (maximum Stream)

Source: Internet
Author: User

Hdu 3572 Task Schedule (maximum Stream)
Hdu 3572 Task Schedule

Description
Our 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.

Input
On 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.

Output
For 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

2
4 3
1 3 5
1 1 4
2 3 7
3 5 9
2 2
2 1 3
1 2 2

Sample Output

Case 1: Yes
Case 2: Yes

The number of tasks and the number of machines are displayed. Each task contains three information: the processing time, start time, and end time of a machine. Ask if all characters can be completed within the time limit of each task. Solution: I have no idea at all. I think this should be a greedy question. Then I went to the question ....... Set a super source point to connect to all tasks. The capacity is the time required to process the task. Then, each task is connected to their corresponding time. For example, if the time limit of a task ranges from 2 to 4, the task node is connected to a time node of 2 to 3 4 with a capacity of 1. Then, all the time nodes are connected to the super settlement point, with the capacity being the number of machines. Pretty clever, but I can't think of it ......
#include 
  
   #include 
   
    #include #include 
    
     #include 
     
      using namespace std;const int INF = 0x3f3f3f3f;const int N = 2500;const int M = 400005;const int FIN = 2015;typedef long long ll;int n, m, s, t, sum;int ec, head[N], first[N], que[N], lev[N];int Next[M], to[M], v[M];void init() {    sum = 0;    ec = 0;    memset(first, -1, sizeof(first));    s = 0, t = FIN;}void addEdge(int a,int b,int c) {    to[ec] = b;    v[ec] = c;    Next[ec] = first[a];    first[a] = ec++;    to[ec] = a;    v[ec] = 0;    Next[ec] = first[b];    first[b] = ec++;}int BFS() {    int kid, now, f = 0, r = 1, i;    memset(lev, 0, sizeof(lev));    que[0] = s, lev[s] = 1;    while (f < r) {        now = que[f++];        for (i = first[now]; i != -1; i = Next[i]) {            kid = to[i];                if (!lev[kid] && v[i]) {                lev[kid] = lev[now] + 1;                    if (kid == t) return 1;                que[r++] = kid;            }        }    }    return 0;}int DFS(int now, int sum) {    int kid, flow, rt = 0;    if (now == t) return sum;    for (int i = head[now]; i != -1 && rt < sum; i = Next[i]) {        head[now] = i;          kid = to[i];        if (lev[kid] == lev[now] + 1 && v[i]) {            flow = DFS(kid, min(sum - rt, v[i]));            if (flow) {                v[i] -= flow;                v[i^1] += flow;                rt += flow;            } else lev[kid] = -1;           }               }    return rt;}int dinic() {    int ans = 0;    while (BFS()) {        for (int i = 0; i <= t; i++) {            head[i] = first[i];        }                   ans += DFS(s, INF);    }    return ans;}   void input() {    int Min = INF, Max = 0;    scanf(%d %d, &n, &m);    int a, b, c;    for (int i = 1; i <= n; i++) {        scanf(%d %d %d, &a, &b, &c);          sum += a;        addEdge(s, i, a);        for (int j = b; j <= c; j++) {            addEdge(i, j + n, 1);           }        if (c < b) swap(c, b);        if (Min > b) Min = b;        if (Max < c) Max = c;    }    for (int i = Min; i <= Max; i++) {        addEdge(i + n, t, m);       }}int main() {    int T, Case = 1;    scanf(%d, &T);    while (T--) {        printf(Case %d: , Case++);        init();        input();        if (dinic() == sum) printf(Yes);        else printf(No);        puts();    }    return 0;}
     
    
   
  

 

Related Article

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.