ps:二分匹配法,匈牙利算法。感觉自己只是学了点皮毛...这里贴上大神的微博,深入浅出的讲了匈牙利算法:
http://blog.csdn.net/dark_scope/article/details/8880547
作者:Dark_Scope
贴上我写的AC代码:
#include "stdio.h"
#include "string.h"
#define true 10000000
#define false 10000001
int K,M,N;
int map[][];
int vis[];
int pri[];
int cal(int n);
int main(){
int i,a,b,num;
while(~scanf("%d",&K) && K){
scanf("%d%d",&M,&N);
memset(map,,sizeof(map));
for(i=;i<=K;i++){
scanf("%d%d",&a,&b);
map[a][b]=;
}
num=;
memset(pri,-,sizeof(pri));
for(i=;i<=M;i++){
memset(vis,,sizeof(vis));
if(cal(i)==true){
num++;
}
}
printf("%d\n",num);
}
return ;
}
int cal(int n){
int x,i;
for(i=;i<=N;i++){
if(!vis[i] && map[n][i]){
vis[i]=;
if(pri[i]==- || cal(pri[i])==true ){
pri[i]=n;
return true;
}
}
}
return false;
}