题目链接:http://poj.org/problem?id=1274
最大图匹配算法分析:http://blog.csdn.net/dark_scope/article/details/8880547
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
bool line[205][205];
int link[205];
bool vis[205];
int m,n;
bool find(int k){
int i,j;
for (int i = 1; i <= n; ++i) //遍历每一个妹子
{
if (line[k][i]&&!vis[i])
{
vis[i]=true;
if(link[i]==0||find(link[i])){
link[i]=k;
return true;
}
}
}
return false;
}
int main(){
freopen("0input.txt","r",stdin);
int t,p,ans;
while(scanf("%d%d",&m,&n)!=EOF){
memset(line,0,sizeof(line));
memset(link,0,sizeof(link));
for (int i = 1; i <= m; ++i)
{
scanf("%d",&t);
for (int j = 0; j < t; ++j)
{
scanf("%d",&p);
line[i][p]=1;
}
}
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://blog.csdn.net/li8630/article/details/45937613