POJ 1325

时间:2022-04-04 18:22:44
 #include<iostream>
#include<stdio.h>
#define MAXN 105
using namespace std; int _m[MAXN][MAXN];
int match[MAXN];
bool ck[MAXN]; bool search(int a,int b,int x)
{
int i;
int t;
for ( i = ; i < b ; i++)
if (_m[x][i] && ! ck[i])
{
ck[i] = true;
t = match[i];
match[i] = x;
if (t == - || search(a,b,t))
return true;
match[i] = t;
}
return false;
} int hungary(int a,int b)
{
memset(match,-,sizeof(match));
int max_match = ;
int i;
for ( i = ; i < a ; i++)
{
memset(ck,false,sizeof(ck));
if (search(a,b,i))
max_match++;
}
return max_match;
} int main()
{
//freopen("acm.acm","r",stdin);
int num_x;
int num_y;
int work;
int x;
int y;
int i;
int tem;
while(cin>>num_x>>num_y>>work)
{
if(num_x == )
break;
memset(_m,,sizeof(_m));
for(i = ; i < work; ++ i)
{
cin>>tem>>x>>y;
if(x*y != )
{
//-- x;
//-- y;
_m[x][y] = ;
}
}
cout<<hungary(num_x,num_y)<<endl;
} }

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

POJ 1325

技术网站地址: vmfor.com