Poj 1698 Alice's chance

Source: Internet
Author: User

The diagram is very important...

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)

At the beginning, the relationship between the work day and the movie was reversed. Let the work day go to the movie, so the number of nodes would be 50 × 20 × 7, too much. In fact, A movie repeats every workday. Why not let the movie go to work? In this way, each film festival will only appear once.

 

Code:

# Include <iostream> <br/> using namespace STD; <br/> # define INF 999999 <br/> int f [375] [375], cap [375] [375]; <br/> int pre [375], RC [375], Q [375], W [51] [8]; <br/> int n, m, ans; <br/> bool BFS () <br/> {<br/> int I, j, head = 0, tail = 1; <br/> memset (RC, 0, sizeof (RC); <br/> pre [0] =-1; <br/> RC [0] = 9999999; <br/> q [tail] = 0; <br/> while (Head <tail) <br/> {<br/> I = Q [++ head]; <br/> for (j = 1; j <= N + M * 7 + 1; j ++) <br/>{< br/> If (Cap [I] [J]> F [I] [J] &! RC [J]) <br/>{< br/> RC [J] = RC [I]; <br/> If (Cap [I] [J]-f [I] [J] <RC [J]) <br/> RC [J] = CAP [I] [J]-f [I] [J]; <br/> pre [J] = I; <br/> q [++ tail] = J; <br/> If (j = N + M * 7 + 1) <br/> return true; <br/>}< br/> return false; <br/>}< br/> void Update () <br/> {<br/> for (INT I = N + M * 7 + 1; I! = 0; I = pre [I]) <br/> {<br/> F [pre [I] [I] + = RC [n + M * 7 + 1]; <br/> F [I] [pre [I] =-f [pre [I] [I]; <br/>}< br/> ans + = RC [n + M * 7 + 1]; <br/>}< br/> void EK () <br/>{< br/> while (BFS () <br/> Update (); <br/>}< br/> int main () <br/> {<br/> int I, J, K, deadline [51], test, sum, day; <br/> CIN> test; <br/> while (test --) <br/>{< br/> scanf ("% d", & N); <br/> memset (F, 0, sizeof (f); <br/> memset (Cap, 0, sizeof (CAP); <br/> M =-1; <br/> sum = 0; <br/> for (I = 1; I <= N; I ++) <br/> {<br/> for (j = 1; j <= 7; j ++) <br/> scanf ("% d", & W [I] [J]); <br/> scanf ("% d ", & day, & deadline [I]); <br/> CAP [0] [I] = day; <br/> If (deadline [I]> m) <br/> M = deadline [I]; <br/> sum + = day; <br/>}< br/> for (I = 1; I <= N; I ++) <br/> for (j = 1; j <= deadline [I]; j ++) <br/> {<br/> for (k = 1; k <= 7; k ++) <br/> {<br/> If (W [I] [k]) <br/> {<br/> CAP [I] [n + (J-1) * 7 + k] + = 1; <br/> CAP [n + (J-1) * 7 + k] [n + M * 7 + 1] = 1; <br/>}< br/> ans = 0; <br/> EK (); <br/> If (ANS = sum) <br/> printf ("Yes/N "); <br/> else <br/> printf ("No/N"); <br/>}< br/> return 0; <br/>} 

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.