POJ 1698 Alice's chance is the topic of the largest stream in the network flow, but it is mainly used to test and create a graph. After the graph is created, just set the template.

Source: Internet
Author: User

A little girl dreamed of becoming a movie star from an early age. Now, there are many movie companies looking for her to make movies, but there may be conflicts between the schedules of these movies, but some girls don't want to miss any chance. They want to take movies from every company, but they don't know if they can take all the movies. All of them find your excellent ACMER to help solve the problem.

The data input is as follows: There are T groups of data. Each group has N, which indicates the number of movies to be taken by her. N <= 20;

Each movie has nine pieces of data. The first seven pieces of data represent the seven days of a week. These seven pieces of data are not 0, that is, indicates that the film can be made on this day, 0 indicates that there are two data records, D, W

D: It takes her D to complete the film. W indicates that D days must be within the first W weeks. This is the answer. Next we will consider how to create an image.

***************************************

Each movie acts as a source point, and then regards every day of every week as a point. Each point can only contribute one working day, that is, the outbound (to the sink point) capacity can only be 1, the size of the inbound edge is also 1, as long as a movie can work on that day, it is possible to select this day, that is, a line is established between the point corresponding to the movie and the point corresponding to the work day. Finally, a super source point is added, the capacity between it and the point of each movie is the work day required for the film (not infinite)

**************************************** *

After creating the OK graph, you can simply determine whether the maximum stream is equal to the sum of the number of days of all movies to be filmed. If it is equal to Yes, No is output.

I also used the code of the previous question to slightly change this question.

The Code is as follows:

/******** PRO: POJ 1698TIT: Alice's ChanceDAT: 2013-08-12AUT: UKeanEMA: huyocan@163.com ****/# include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <queue> # define INF 1e9using namespace std; queue <int> que; // The int M queue used for extensive search; // M indicates the number of int s, t; // source point and sink point int flow [405] [405]; // residual traffic int p [405]; // The parent node array of the wide search record path int a [405]; // minimum residual volume on the path int cap [405] [405]; // capacity network int ans; // maximum stream int data [30] [10]; // store and read data Int sum; // number of days required for saving all movies int read () {int flim_num; cin> flim_num; for (int I = 0; I <flim_num; I ++) for (int j = 0; j <9; j ++) cin> data [I] [j]; s = 0; t = 1; // for (int I = M = 0; I <flim_num; I ++) M = max (data [I] [8], M ); M = M * 7 + 30; // calculate the approximate total number of memset (cap, 0, sizeof (cap); // 2 -- 21 is a movie, point after 22 represents time for (int I = 2; I <flim_num + 2; I ++) cap [0] [I] = data [I-2] [7]; // super source to the edge of each movie // process the movie to the everyday for (int I = 0; I <flim_num; I ++) for (int j = 0; j <7; j ++) // j is the day of the week. if (data [I] [J] = 1) for (int k = 0; k <data [I] [8]; k ++) // The Week of k {cap [I + 2] [k * 7 + j + 22] = 1; // The size of the edge of the movie to the day cap [k * 7 + j + 22] [1] = 1; // The size of the edge from the day to the vertex} sum = 0; for (int I = 0; I <flim_num; I ++) sum + = data [I] [7]; // calculate the number of days required to complete all movies; return 1;} int deal () // augmented Path Algorithm {memset (flow, 0, sizeof (flow); ans = 0; while (1) {memset (a, 0, sizeof (a); a [s] = INF; que. push (s); while (! Que. empty () {int u = que. front (); que. pop (); for (int v = 1; v <= M; v ++) if (! A [v] & cap [u] [v]-flow [u] [v]> 0) {p [v] = u; que. push (v); a [v] = min (a [u], cap [u] [v]-flow [u] [v]); // minimum residual traffic on the path} if (a [t] = 0) break; for (int u = t; u! = S; u = p [u]) {flow [p [u] [u] + = a [t]; flow [u] [p [u]-= a [t];} ans + = a [t];} // cout <ans <endl; return ans;} int main () {int T; cin> T; while (T --) {read (); if (deal () = sum) puts ("Yes"); elseputs ("No");} 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.