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; }