POJ 3041 (minimum point coverage)

Source: Internet
Author: User

Test instructions

If you are now in a n*n matrix with K-obstacles in it, you have a weapon that can destroy one row or one row of obstacles at a time, and the smallest ammo will destroy all obstacles.

input is: N K
Then there are k lines, each line including the coordinates of the obstacle, that is, the R row C column;
Such as:
3 4
1 1
1 3
2 2
3 2

Output is: The minimum amount of ammo spent

Idea: Set the I row as the X collection. Sets the J column as the Y collection. So the original problem-with the fewest shells knocked out all the obstacles, converted to such a problem:

Select as few points as possible in the binary chart so that at least one end of each edge is selected

Bare minimum point coverage problem, using the conclusion: the minimum coverage number equals the maximum match number can be

The code is as follows:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int N = 600;int N, k;bool lin[n][n];int used[n], arr[n];bool find (int x) {for (int j = 1; J <= N; j + +) {if (lin[x ][J] = = True && used[j] = = 0) {Used[j] = 1;if (arr[j] = = 0 | | find (ARR[J])) {Arr[j] = X;return true;}} return false;} int main () {int R, C;while (~scanf ("%d%d", &n, &k)) {memset (Lin, False, sizeof (Lin)); memset (arr, 0, sizeof (arr)); for (int i = 1; I <= K; i++) {scanf ("%d%d", &r, &c); Lin[r][c] = true;} int all = 0;for (int i = 1; I <= n; i++) {memset (used, 0, sizeof (used)); if (find (i)) all++;} printf ("%d\n", All);} return 0;}


POJ 3041 (minimum point 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.