HDU 3572 "Max Stream + array open small meeting tle"

Source: Internet
Author: User

Test instructions: There are M machines, there are n tasks. Each task must be done in SI or later, completed before EI or, the completion task must process the PI time unit. where each task can work on any (idle) machine, each machine can only work one task at a time, and each task can only be worked by one machine at a time, and the task is half-interrupted and taken to other machines. Can you finish the task within the stipulated time?

The map is simply classic. Just beginning to see is also a face, also want to use greedy to engage in a mess. But the vegetarian feel can't do it.
The correct idea is to use the maximum flow of the network stream.
S is connected with each task, the capacity is P, each task is connected with the corresponding time period, the capacity is 1, each point of time with the T edge, the capacity is M.
is not very clever, a look to understand, but completely can't think out

#include <stdio.h> #include <string.h> #include <queue> #include <iostream> #define MAX 510000# Define INF 0x3f3f3f3fusing namespace Std;int ss, Tt;int kase;int sum;int N, m;int cont;int head[max];int divv[max];int cur [max];struct Edge {int from, to, W, next;}    e[max];void Add (int u, int v, int w) {e[cont].from = u;    E[cont].to = v;    E[CONT].W = W;    E[cont].next = Head[u]; Head[u] = cont++;}    int Makediv () {memset (DIVV, 0, sizeof (DIVV));    DIVV[SS] = 1;    Queue<int> Q;    Q.push (ss); while (!        Q.empty ()) {int u = q.front ();        if (U = = TT) return 1;        Q.pop ();            for (int i = head[u]; i =-1; i = e[i].next) {int w = E[I].W;            int v = e[i].to;                if (divv[v] = = 0 && w) {divv[v] = Divv[u] + 1;            Q.push (v); }}} return 0;}    int DFS (int u, int maxflow, int tt) {if (U = = TT) return maxflow;    int ret = 0; for (int &Amp;i = Cur[u]; I! =-1;        i = e[i].next) {int v = e[i].to;        int w = E[I].W;            if (divv[v] = = Divv[u] + 1 && w) {int f = DFS (V, Min (Maxflow-ret, W), TT);            E[I].W-= f;            e[i ^ 1].W + = f;            RET + = f;        if (ret = = Maxflow) return ret;    }} if (ret) return ret;        else {Divv[u] = 0;    return 0;    }}void dinic () {int ans = 0;        while (makediv () = = 1) {memcpy (cur, head, sizeof (head));    Ans + = DFS (ss, INF, TT);    } if (ans = = sum) printf ("Case%d:yes\n\n", ++kase); else printf ("Case%d:no\n\n", ++kase);}    int main (void) {int t;    scanf ("%d", &t);    Kase = 0;        while (t--) {sum = 0;        SS = 0;        Cont = 0;        Memset (Head,-1, sizeof (head));        scanf ("%d%d", &n, &m);        int maxx = 0;        tt = 2 + n + +;        int p, S, E; for (int i = 1; I <= n; i++) {scanf ("%d%d%d ", &p, &s, &e);            sum + = p;            if (E > Maxx) maxx = e;            Add (ss, i + A, p);            Add (i + A, SS, 0);                for (int j = s; J <= E; j + +) {Add (i + A, J, 1);            Add (J, i + 500, 0);            }} for (int i = 1; I <= Maxx; i++) {Add (I, TT, M);        Add (TT, I, 0);    } dinic (); } return 0;}

HDU 3572 "Max Stream + array open small meeting tle"

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.