- topic 237
- topic information
- run result
- line
- discussion area
The time limit of the game Master's annoyance: +Ms | Memory Limit:65535KB Difficulty:5
-
-
Describe
-
There is a legendary game master, in the leisure time played a small game, in the game, a n*n block-shaped area with many enemies, players can use bombs to blow up a row or a column of all enemies. He is a man who wants to play all kinds of games, so he decides to use as few bombs as possible to blow up all the enemies.
Now give you a status of the game, please help him to judge how many bombs needed at least to blow up all the enemies.
For example, the X represents the enemy
X. X
. X.
. X.
Then, he only needs to blow up the 1th and 2nd columns to blow up all the enemies, so only two bombs are needed.
-
-
Input
-
The
-
first line is an integer T that represents the number of groups of test data (0<t<=400).
The first row of each set of test data has two integer n,k, where n represents the size of the game's Square area. (N<=500,k<=10 000)
The subsequent K-line, with two integers per line, i,j denotes line I, and Column J has an enemy (both rows and columns are numbered starting with 1). (1<=i,j<=n)
-
-
Output
-
-
for each set of test data, output an integer representing the minimum number of bombs required
-
-
Sample input
-
-
13 41 11 32 23 2
-
-
Sample output
-
-
2
-
-
Source
-
-
Poj translated.
-
-
Uploaded by
-
-
Zhang Yunzun
Test instructions is to use the least amount of bombs to eliminate all enemies, which is the minimum point coverage.
The minimum point overlay can be achieved by a maximum match.
The best algorithm to find the most matches is the Hungarian algorithm
And how the composition in this question becomes a difficult place to understand. We can think of that.
Because bombs can blow up a row or a column
If there is an enemy in row J of line I, it can be imagined that I and J Point are related.
The question becomes click Open link
#include <stdio.h> #include <vector> #include <string.h>using namespace std;vector<int>map[ 505];bool vis[505];int conn[505];bool dfs (int x) {for (int i=0;i<map[x].size (); i++) {int y=map[x][i];if (!vis[y]) {Vis [Y]=true;if (conn[y]==0| | DFS (Conn[y])) {Conn[y]=x;return true;}}} return false;} int main () {int ncase;scanf ("%d", &ncase), while (ncase--) {int N,k;memset (CONN,0,SIZEOF (conn)); Memset (map,0, sizeof (map); scanf ("%d%d", &n,&k), for (int i=0;i<k;i++) {int a,b;scanf ("%d%d", &a,&b); Map[a].push _back (b);} int ans=0;for (int i=1;i<=n;i++) {memset (vis,false,sizeof (VIS)); if (Dfs (i)) ans++;} printf ("%d\n", ans);} return 0;}
nyoj237 Game Master's annoyance (minimum point coverage)