Poj 3020: Antenna placement (minimum path overwrite of undirected Bipartite Graph)

Source: Internet
Author: User

Antenna placement
Time limit:1000 ms   Memory limit:65536 K
Total submissions:6334   Accepted:3125

Description

The global aerial research centre has been allotted the task of building the maximum th generation of mobile phone nets in Sweden. the most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. it is called 4 dair, and comes in four types. each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the Earth. the four types correspond to antennas operating in the directions north, west, south, and East, respectively. below is an example picture of places of interest, depicted by twelve small rings, and nine 4 Dair antennas depicted by ellipses covering them.
 
Obviusly, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. we model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of a either is a point of interest, which must be covered by at least one antenna, or empty space. antennas can only be positioned at an entry in. when an antenna is PLA CED at row R and column C, this entry is considered covered, but also one of the neighbouring entries (C + 1, R), (C, R + 1), (C-1, r), or (c, R-1), is covered depending on the type chosen for this particle antenna. what is the least number of antennas for which there exists a placement in a such that all points of interest are covered?

Input

On the first row of input is a single positive integer N, specifying the number of scenarios that follow. each scenario begins with a row containing two positive integers H and W, with 1 <= H <= 40 and 0 <W <= 10. thereafter is a matrix presented, describing the points of interest in Sweden in the form of H lines, each containing W characters from the set ['*', 'O']. A '*'-character symbolises a point of interest, whereas a 'O'-character represents open space.

Output

For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.

Sample Input

27 9ooo**oooo**oo*ooo*o*oo**o**ooooooooo*******ooo*o*oo*oo*******oo10 1***o******

Sample output

175


Okay .. A few simple Hungarian algorithms and simple minimum coverage are implemented .. Finally, I encountered a tangled question ..

I have read the question parsing (orz) of xiaoyou sauce and click the link to open it. It is really very detailed to write the problem-solving report ..

I learned a lot from him or her .. Thank you very much .. Even though he or she does not know me .. (233)


Least path overwrite of undirected bipartite graph = number of vertices-Maximum number of bipartite matching/2


# Include <cstdio> # include <cstring> # include <algorithm> # include <iostream> using namespace STD; const int M = 1000 + 5; int DX [] = {-,}; int dy [] = {,-}; int T, M, N; // input data int link [m]; // used to determine whether it is a saturation point. Int City [m] [m]; // used to record the int V1, V2 cities; // The Int sum graph created after splitting; // bool map of the total number of cities [m] [m]; // The created bool cover [m]; // It is used to check whether it is a coverage point int ans; // maximum allocation value char STR; // used to input the string bool DFS (int x) // The Hungarian algorithm {for (INT y = 1; y <= V2; y ++) {If (Map [x] [Y] &! Cover [y]) {cover [y] = true; If (! Link [y] | DFS (link [y]) {link [y] = x; return true ;}} return false ;} int main () {scanf ("% d", & T); While (t --) {memset (city, 0, sizeof (city); memset (link, 0, sizeof (Link); memset (MAP, false, sizeof (MAP); ans = 0; V1 = 0; v2 = 0; sum = 0; scanf ("% d", & N, & M); For (INT I = 1; I <= N; I ++) for (Int J = 1; j <= m; j ++) {CIN> STR; If (STR = '*') {City [I] [J] = ++ sum ;}} for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= m; j ++) if (City [I] [J]) for (int K = 0; k <4; k ++) if (City [I + dx [k] [J + dy [k]) map [City [I] [J] [City [I + dx [k] [J + dy [k] = true; V1 = v2 = sum; for (INT I = 1; I <= V1; I ++) {memset (cover, false, sizeof (cover); If (DFS (I )) ans ++;} printf ("% d \ n", Sum-ans/2); // undirected bipartite graph: minimum path overwrite = number of vertices in the source image before "split"-Maximum number of matching/2} return 0 ;}


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.