Poj 1548 robots
Question Link
At first glance, I thought it was the problem DP on the White Paper. In fact, it was not. I just asked a total of several robots to cover all the paths.
Idea: The minimum path coverage problem. If one point is located at the bottom right of the other point, create an edge and run the minimum path coverage command.
Code:
#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] == -1 || dfs(left[v])) {left[v] = u;return true;}}return false;}int hungary() {int ans = 0;memset(left, -1, 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] == -1 && y[0] == -1) 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\n", cnt - hungary());cnt = 1;}return 0;}
Poj 1548 robots (minimum path coverage)