alice& #39; s chance

Source: Internet
Author: User

id=1698 "style=" Background-color:rgb (51,255,51) > Topic Links

    • Serie A champions:
      Alice is going to make a film. There are n films, which stipulate that Alice I film will be able to make movies in only a few days of a week, and only in the previous WI weeks, and this film will be the end of a di days. Ask Alice if she can make a movie in full.
      The first line represents how many sets of data, for each group of data the first row represents the N movie, the next 2 to n+1 lines, each row represents a movie, 9 numbers per row, 7 numbers in front, 1 for the clap. 0 means no, the 8th number represents a few days, and the 9th number represents a couple of weeks to shoot
    • Analysis:
      For every one of the movies. DI-X[0]-x[1]-...-x[t] = 0,di Indicates the number of days required for this movie, x[] Indicates whether the movie is selected for these days (value zero or one)
      For every single day. Y[0]-y[1]-...-y[t] <= said that it was the day to make a movie. Y[] Indicates whether the corresponding movie is taken on this day (value zero or one)
struct edge{int from, to, cap, flow; BOOL operator< (const edge& RHS) Const {return from < Rhs.from | |    (from = = Rhs.from && to < rhs.to);    }};const int MAXV = 500;struct isap{int n, m, S, t;    Vector<edge> edges;   Vector<int> G[MAXV]; adjacency table.        G[I][J] indicates that the J-side of node I in the e array ordinal bool VIS[MAXV];           BFS using int D[MAXV];        Distance from starting point to I int CUR[MAXV];          Current arc pointer int P[MAXV];        Can be augmented on the road on an arc int NUM[MAXV];        Distance designator count void Addedge (int from, int. to, int cap) {Edges.push_back (Edge) {from, to, Cap, 0});        Edges.push_back (Edge) {To, from, 0, 0});        m = Edges.size ();        G[from].push_back (m-2);    G[to].push_back (m-1);        } bool BFS () {memset (Vis, 0, sizeof (VIS));        Queue<int> Q;        Q.push (t);        Vis[t] = 1;        D[t] = 0; while (!            Q.empty ()) {int x = Q.front ();            Q.pop (); REP (i, g[x].size()) {edge& e = edges[g[x][i]^1];                    if (!vis[e.from] && e.cap > E.flow) {vis[e.from] = 1;                    D[e.from] = d[x] + 1;                Q.push (E.from);    }}} return vis[s];        } void ClearAll (int n) {this->n = n;        REP (i, N) g[i].clear ();    Edges.clear ();    } void Clearflow () {REP (I, Edges.size ()) Edges[i].flow = 0;        } int Augment () {int x = t, a = INF;            while (x! = s) {edge& E = edges[p[x]];            A = min (A, e.cap-e.flow);        x = Edges[p[x]].from;        } x = t;            while (x! = s) {Edges[p[x]].flow + = A;            Edges[p[x]^1].flow-= A;        x = Edges[p[x]].from;    } return A;        } int Maxflow (int s, int t, int need) {this->s = s;        This->t = t;int flow = 0;        BFS ();        memset (num, 0, sizeof (num));        REP (i, n) num[d[i]]++;        int x = s;        memset (cur, 0, sizeof (cur));                while (D[s] < n) {if (x = = t) {flow + = Augment ();                if (flow >= need) return flow;            x = S;            } int ok = 0;                FF (i, cur[x], g[x].size ()) {edge& E = edges[g[x][i]];                    if (E.cap > E.flow && d[x] = = D[e.to] + 1)//Advance {OK = 1;                    P[e.to] = G[x][i]; CUR[X] = i;                    Note x = e.to;                Break }} if (!ok)//Retreat {int m = n-1;//Initial value attention REP (I, g[x]                    . Size ()) {edge& E = edges[g[x][i]]; if (E.cap > E.flow) m = min (M, d[e.To]);                } if (--num[d[x]] = = 0) break;                Num[d[x] = m + 1]++; Cur[x] = 0;            Note if (x! = s) x = Edges[p[x]].from;    }} return flow;        } vector<int> Mincut ()//Call the after Maxflow {BFS ();        Vector<int> ans;            REP (i, edges.size ()) {edge& e = edges[i];        if (!vis[e.from] && vis[e.to] && e.cap > 0) ans.push_back (i);    } return ans;    } void Reduce () {REP (I, Edges.size ()) edges[i].cap-= Edges[i].flow;        } void Print () {printf ("graph:\n");    REP (i, edges.size ()) printf ("%d->%d,%d,%d\n", Edges[i].from, Edges[i].to, Edges[i].cap, Edges[i].flow);    }} mf;int Day[18];int main () {int T, n, D, W;    RI (T);        FE (Kase, 1, T) {int sum = 0;        RI (n); Mf. CLEARALL (n+ 7 * 50 + 2);        int S = 0, T = n + 7 * + 1, Max =-1;            Fe (i, 1, n) {Fe (J, 1, 7) RI (Day[j]);            RII (d, W);            sum + = D;            max = MAX (max, W); Mf.            Addedge (S, I, D); FE (J, 1, 7) if (Day[j]) {REP (k, W) MF.                Addedge (i, n + k * 7 + J, 1); }} FE (I, 1, 7) REP (J, Max) MF.        Addedge (n + J * 7 + I, T, 1); printf ("%s\n", MF. Maxflow (S, T, INF) = = sum?    "Yes": "No"); } return 0;}


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

alice& #39; s chance

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.