标签:des style blog http color io os ar for
6 3 3 1 1 1 2 1 3 2 1 2 3 3 1 0
3二分图匹配,匈牙利算法(用增广路径求二分图最大匹配的算法)学习http://blog.csdn.net/dark_scope/article/details/8880547#include<cstdio> #include<cstring> bool map[505][505],vis[505]; int p[505],n,m; bool find(int x) { int i; for(i=1;i<=n;i++)//遍历每个男生 { if(!vis[i]&&map[x][i]) { vis[i]=1; if(!p[i]||find(p[i]))//这个男生还没有partner或者可以挪出来 { p[i]=x; return 1; } } } return 0; } int main() { int i,j,k,a,b,ans; while(scanf("%d",&k),k) { ans=0; scanf("%d%d",&m,&n); memset(map,0,sizeof map); memset(p,0,sizeof p); for(i=1;i<=k;i++) { scanf("%d%d",&a,&b); map[a][b]=1; } for(i=1;i<=m;i++)//给每个女生找partner { memset(vis,0,sizeof vis);//每次男生标记清零 if(find(i)) ans++; } printf("%d\n",ans); } return 0; }
标签:des style blog http color io os ar for
原文地址:http://blog.csdn.net/u013776243/article/details/39962369