hdu2063 basic binary map matching, Amway a good article

Source: Internet
Author: User

The reason for writing this question is because I saw a particularly good Amway article and then wrote it all down in case you forgot the Hungarian algorithm later.

Topic Link http://acm.hdu.edu.cn/showproblem.php?pid=2063

Amway article link http://blog.csdn.net/dark_scope/article/details/8880547 thank you Big Ben.

is to sweep once, give each boy to try this to find a girl if can't find, let the front already paired first break, then find, if still can't find, on.

It's better to write. Then directly set the template on it, I really do not understand to read the article it.

#include <stdio.h> #include <string.h> #define Manx 505 using namespace Std;
BOOL Line[manx][manx];
BOOL Used[manx];
int k,m,n;

int Boys[manx]; BOOL Find (int x) {for (int. j=1;j<=n;j++) {if (line[x][j]&&used[j]==0) {use
            D[j]=1; if (boys[j]==0| |
                Find (Boys[j])) {boys[j]=x;

            return 1;
}}} return 0;
        } int main () {while (~SCANF ("%d", &k)) {if (k==0) break;
        scanf ("%d%d", &m,&n);
            for (int i=0;i<manx;i++) memset (line[i],0,sizeof (Line[i]));
        Memset (Boys,0,sizeof (boys));
        int A, B;
            for (int i=0;i<k;i++) {scanf ("%d%d", &a,&b);

        Line[a][b]=1;
        } int ans=0;
            for (int i=1;i<=m;i++) {memset (used,0,sizeof (used));
        if (find (i)) ans+=1;
    } printf ("%d\n", ans);
}    return 0; }


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.