POJ 3020 Antenna Placement
解题思路:求解最大独立集,转而求解最小顶点覆盖->最大流问题
#include <iostream>
using namespace std;
int t;
int father[405];
bool visit[405];
struct
{
int x,y;
}point[405];
int Search(int x)
{
for (int i = 1; i < t; i++)
{
if (!visit[i] && (abspoint[x].x - point[i].x) + abs(point[x].y - point[i].y)) == 1)
{
visit[i] = true;
if (father[i] == 0 || Search(father[i]))
{
father[i] = x;
return 1;
}
}
}
return 0;
}
int main()
{
int k, n, m, u, v, s, row, col;
char ch;
const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
cin >> k;
while (k--)
{
memset(father, 0, sizeof(father));
t = 1; s = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
cin >> ch;
if (ch == '*')
{
point[t].y = i;
point[t++].x = j;
}
}
for (int i = 1; i < t; i++)
{
memset(visit, 0, sizeof(visit));
s += Search(i);
}
t = t - s / 2 - 1;
cout << t << endl;;
}
return 0;
}