POJ-1698 Alice's Chance (binary graph multiple match)

Source: Internet
Author: User

A person, want to see n performances, each performance need to see K times
Now give the weekly schedule for each show, and the closing date of the show
Ask if this guy can finish all the movies.

Problem-solving ideas: Two-figure multi-match can be done, the maximum flow can also be done, here only the binary graph maximum matching
350 days is set to a point set, each show is set to another point set, the capacity is to see the number of times, the relationship between the day is whether there is a performance

#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define N#define M 10010#define Sintday[7], G[n][s], Vlink[s], link[s][n], cap[s];intN, tot, Sum;BOOLVis[n], route[s];voidInit () {memset(Vis,0,sizeof(VIS));memset(g,0,sizeof(g));memset(Vlink,0,sizeof(Vlink)); tot =0;scanf("%d", &n);intD, W; Sum =0; for(inti =0; I < n; i++) { for(intj =0; J <7; J + +) {scanf("%d", &day[j]); }scanf("%d%d", &cap[i], &w); Sum + = Cap[i]; for(intj =0; J <7; J + +) {if(Day[j]) { for(intK =0; K < W; k++) {G[k *7+ J][i] =true; Vis[k *7+ j] =true; }            }        }    }}BOOLDfsintu) { for(inti =0; I < n; i++) {if(!route[i] && g[u][i]) {Route[i] =true;if(Vlink[i] < cap[i]) {Link[i][++vlink[i]] = u;return true; } for(intj =1; J <= Vlink[i]; J + +) {if(Dfs (Link[i][j])) {Link[i][j] = u;return true; }            }        }    }return false;}voidSolve () {intAns =0; for(inti =0; I < -; i++)if(Vis[i]) {memset(Route,0,sizeof(route));if(Dfs (i))            {ans++; }        }if(ans = = Sum)printf("yes\n");Else        printf("no\n");}intMain () {intTestscanf("%d", &test); while(test--)        {init ();    Solve (); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ-1698 Alice's Chance (binary graph multiple match)

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.