标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063
最大匹配模板题;
#include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <stack> #include <cstring> using namespace std; #define N 1100 int used[N], vis[N], maps[N][N], n, m; bool Find(int u) { for(int i=1; i<=n; i++) { if(!vis[i] && maps[u][i])//判断是否被增广过并且愿意与男生i在一起; { vis[i] = 1; if(!used[i] || Find(used[i]))//判断男生i是否被人占用,或者协商成功; { used[i] = u; return true; } } } return false; } int main() { int k,a ,b; while(scanf("%d", &k),k) { memset(maps, 0, sizeof(maps)); memset(used, 0, sizeof(used)); memset(vis, 0 ,sizeof(vis)); scanf("%d%d", &m, &n); while(k--) { scanf("%d%d", &a, &b); maps[a][b] = 1; } int ans = 0; for(int i=1; i<=m; i++) { memset(vis, 0 ,sizeof(vis)); if(Find(i)) ans++; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhengguiping--9876/p/4713195.html