The first preview is Baidu's algorithm and then learn a bit
And then found a senior's PPT and learned a bit.
Found.. It's not the same.
I have tried to find a template problem. Baidu's bad use is WA, anyway. Sure enough, you should follow the seniors.
The points on each side of the graph are the number of rows and columns
Each one has a point where the ranks are connected to one side.
Ask for the minimum point coverage
And then stuck ... Later saw the increase Lin's blog ...
Minimum point overwrite = maximum number of matches is a template problem.
Then WA.
It was later discovered that when the left-hand side of the loop was to be mem once a vis array
It should be re-emptied before each search. Or how to find it next time ... Is it not necessary to be visited by the road to the point?
#include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <math.h >using namespace Std;int s[505][505];int vis[505];int n,m;int link[505];bool Find (int i) {for (int k=1;k<=n;k+ +) { if (s[i][k]==1&&vis[k]==0) { vis[k]=-1; if (link[k]==-1| | Find (Link[k])) { link[k]=i; return true;}} } return false;} int main () {while (~scanf ("%d%d", &n,&m)) { memset (s,0,sizeof (s)); memset (link,-1,sizeof (link)); for (int i=1;i<=m;i++) { int a, b; scanf ("%d%d", &a,&b); s[a][b]=1; } int ans=0; for (int i=1;i<=n;i++) { memset (vis,0,sizeof (Vis)); if (find (i)) { ans++; } } printf ("%d\n", ans);}}
POJ 3041 Hungarian algorithm template problem