题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255
题解:KM模版题。
#include
#include
#define INF 0x3f3f3f3f
#define MAXN 302
int w[MAXN][MAXN],match[MAXN],n;
int lx[MAXN],ly[MAXN],slack[MAXN];
int visitx[MAXN],visity[MAXN];
int Scan()
{
char ch;
int ret=0;
while((ch=getchar())<'0'||ch>'9');
while(ch>='0'&&ch<='9')
{
ret=ret*10+(ch-'0');
ch=getchar();
}
return ret;
}
int find(int x)//匈牙利算法
{
int i,temp;
visitx[x]=1;
for(i=0;itemp?temp:slack[i];
}
}
return 0;
}
void KM()
{
int i,j,d;
memset(ly,0,sizeof(ly));
memset(match,-1,sizeof(match));
for(i=0;ilx[i])
lx[i]=w[i][j];
}
for(i=0;islack[j])
d=slack[j];
}
for(j=0;j