POJ2239 Selecting Courses "binary graph maximum Match"

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=2239


Main topic:

The school has a total of n courses, and the school stipulates that 12 knots are available every day, 7 days a week. Give you the number of times per week, and which day of each course

class on the. If you have multiple courses in the same class on the same day, then you can only choose one of them. So here's the question: How much can you choose at the same time?

Course without conflict.


Input Description:

First give you an n, indicating that there are N courses. The next n lines, the first digit x for each line, represent the course of the week. Next is the X logarithm. The

A number d indicates which day of the week, and the second number C indicates which class is on this day.


Ideas:

This problem is seen to be a two-point map matching. Create a dichotomy that represents a course, while representing a class (7*12 a week of lessons

number 1~7 * 12来 arrangement). The course and the course of a class corresponding to the construction of the side, and then find the maximum matching number of the two graphs. Here with Hungarian teeth .

DFS edition to do.


AC Code:

#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;const int maxn = 330;int map[maxn][maxn];int mask[maxn];int n,m;int cx[maxn],cy[maxn];int FindPath (int u) {for (int i = 1; I <= M; ++i) {if (Map[u][i] &&!            Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | |                Findpath (Cy[i])) {Cy[i] = u;                Cx[u] = i;            return 1; }}} return 0;}    int Maxmatch () {int res = 0;    for (int i = 1; I <= N; ++i) cx[i] = 1;    for (int i = 1; I <= M; ++i) cy[i] = 1;                for (int i = 1; I <= N, ++i) {if (cx[i] = = 1) {for (int j = 1; j <= M; ++j)            MASK[J] = 0;        Res + = Findpath (i); }} return res;}    int main () {int a,b,id;        while (~SCANF ("%d", &n)) {memset (map,false,sizeof (MAP));        M = 7*12; for (int i = 1; I <= N; ++i) {scanf ("%d", &id);                for (int j = 1; j <= id; ++j) {scanf ("%d%d", &a,&b);            map[i][(A-1) *12+b] = 1;    }} printf ("%d\n", Maxmatch ()); } return 0;}


POJ2239 Selecting Courses "binary graph maximum Match"

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.