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)