Poj 1548 robots (minimum path coverage)

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.