POJ 1548 Robots
题目链接
题意:乍1看还以为是小白上那题dp,其实不是,就是求1共几个机器人可以覆盖所有路径
思路:最小路径覆盖问题,1个点如果在另外一个点右下方,就建边,然后跑最小路径覆盖便可
代码:
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 25 * 25;
int x[N], y[N], cnt = 1;
vector<int> g[N];
bool judge(int i, int j) {
return x[j] >= x[i] && y[j] >= y[i];
}
int left[N], vis[N];
bool dfs(int u) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (vis[v]) continue;
vis[v] = 1;
if (left[v] == ⑴ || dfs(left[v])) {
left[v] = u;
return true;
}
}
return false;
}
int hungary() {
int ans = 0;
memset(left, ⑴, sizeof(left));
for (int i = 0; i < cnt; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i)) ans++;
}
return ans;
}
int main() {
while (~scanf("%d%d", &x[0], &y[0])) {
if (x[0] == ⑴ && y[0] == ⑴) break;
while (~scanf("%d%d", &x[cnt], &y[cnt])) {
if (x[cnt] == 0 && y[cnt] == 0) break;
cnt++;
}
for (int i = 0; i < cnt; i++) {
g[i].clear();
for (int j = 0; j < i; j++) {
if (judge(i, j)) g[i].push_back(j);
if (judge(j, i)) g[j].push_back(i);
}
}
printf("%d
", cnt - hungary());
cnt = 1;
}
return 0;
}