原题:http://acm.hdu.edu.cn/showproblem.php?pid=1281
题意:
求的三个数 — — 1、cas数;2、特殊边的数量(所谓特殊边即不连该条边会使得最大匹配数减少);3、最大匹配数;
#include<stdio.h>
#include<string.h>
const int maxn = 110;
int n, m, k;
int cas = 0;
bool link[maxn][maxn], used[maxn];
int match[maxn];
bool find(int x)
{
for(int i = 1;i<=m;i++)
{
if(link[x][i] && !used[i])
{
used[i] = true;
if(match[i] == 0 || find(match[i]))
{
match[i] = x;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d%d", &n, &m, &k)!=EOF)
{
int sum = 0, cnt = 0;
memset(link, false, sizeof link);
memset(match, 0, sizeof match);
for(int i = 1;i<=k;i++)
{
int x, y;
scanf("%d%d", &x, &y);
link[x][y] = true;
}
for(int i = 1;i<=n;i++)
{
memset(used, false, sizeof used);
if(find(i))
sum++;
}
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=m;j++)
{
if(link[i][j])
{
memset(match, 0, sizeof match);
int w = 0;
link[i][j] = false;
for(int i = 1;i<=n;i++)
{
memset(used, false, sizeof used);
if(find(i))
w++;
}
if(w<sum)
cnt++;
link[i][j] = true;
}
}
}
printf("Board %d have %d important blanks for %d chessmen.\n", ++cas, cnt, sum);
}
return 0;
}