--hdu1281-> binary Graph maximum match (unique match judgment)

Source: Internet
Author: User

D-board GameTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 1281Appoint Description:System Crawler (2015-08-02)

Description

Xiaoxi and Gardon are playing a game: on a n*m board, in the grid to put as much as possible in some chess inside the "car", and so they can not attack each other, which is of course very simple, but Gardon limited only certain lattice can be put, Xiaoxi is still easy to solve the problem (see) Note that the location of the car does not affect the car's mutual attack.
So now Gardon want to let Xiao-Xi to solve a more difficult problem, in order to ensure as much as possible "car" premise, some of the board can be avoided, that is, not on these squares to put the car, but also to ensure that as much as possible "car" was put down. However, if some lattice does not put the son, there is no guarantee to put as much as possible "car", such a lattice is called to do important points. Gardon want to figure out how many of these important points, can you solve this problem?

Input

Input contains multiple sets of data,
The first line has three numbers N, M, K (1<n,m<=100 1<k<=n*m), indicating the height and width of the board, and the number of squares that can be put "cars". The next K-line describes all the lattice information: two x and y per line, indicating the position of the lattice in the checkerboard.

Output

For each set of data entered, output in the following format:
Board T has C important blanks for L chessmen.

Sample Input

3 3 4 1 2 1 3 2 1 2 2 3 3 4 1 2 1 3 2 1 3 2

Sample Output

Board 1 has 0 important blanks for 2 chessmen. Board 2 has 3 important blanks for 3 chessmen. First find a maximum match, then remove each match, and then find the maximum binary match, if not required, then the maximum number of matches is removed and not affected.
#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int ms[101][101],             Match[101],vis[101];int n,m;int Hungray (int u) {for (int i = 1;i<=m;i++) {if (Ms[u][i] && vis[i] = = 0) {            Vis[i] = 1; if (match[i] = = 0| |                Hungray (Match[i])) {Match[i] = u;            return 1; }}} return 0;}    int main () {int k;    int c = 1;        while (~SCANF ("%d%d%d", &n,&m,&k)) {int ans,res;        Ans = res = 0;        memset (ms,0,sizeof (ms));        memset (match,0,sizeof (match));        int x, y;            for (int i = 0;i<k;i++) {scanf ("%d%d", &x,&y);        Ms[x][y] = 1;            } for (int i = 1;i<= n;i++) {memset (vis,0,sizeof (VIS));        if (Hungray (i)) ans + +;        } int match1[101];        for (int i = 1;i<=m;i++) match1[i] = Match[i];      for (int i = 1;i<= m;i++) {memset (match,0,sizeof (match));      int ans1 = 0;                if (Match1[i]) {//printf ("matches:%d%d\n", match[i],i);                Ms[match1[i]][i] = 0;                    for (int j = 1;j<=n;j++) {memset (vis,0,sizeof (VIS));                if (Hungray (j)) ans1++;                } if (Ans1 < ans) res++;            Ms[match1[i]][i] = 1;        }}//printf ("%d%d\n", Res,ans);    printf ("Board%d has%d important blanks for%d chessmen.\n", C++,res,ans); }}

  

--hdu1281-> binary Graph maximum match (unique match judgment)

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.