Poj3020 maximum binary match

Source: Internet
Author: User
Antenna placement
Time limit:1000 ms   Memory limit:65536 K
Total submissions:5486   Accepted:2743

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 placed 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
# Include <iostream> using namespace STD; int ipmap [41] [11]; // mark the location of the city '*' and record the city id int IP in sequence; // city number (eventually the number of cities) int V1, V2; // two vertex sets int m in the bipartite graph; // The maximum binary match bool City [401] [401]; // mark whether two cities can be connected. // split each city into two cities by means of the "split point" operation, belongs to the two points set bool vist [401]; int link [401]; int dire_r [4] = }; int dire_c [4] = {,-}; // corresponds to the top, bottom, left, right, and * Hungary algorithm */bool DFS (int x) {for (INT y = 1; y <= V2; y ++) if (City [x] [Y] &! Vist [y]) {vist [y] = true; If (link [y] = 0 | DFS (link [y]) {link [y] = X; return true ;}} return false;} void search (void) {for (INT x = 1; x <= V1; X ++) {memset (vist, false, sizeof (vist); If (DFS (x) m ++;} return;} int main (void) {int test, H, W; CIN> test; while (test --) {/* Initial */memset (ipmap, 0, sizeof (ipmap); memset (city, false, sizeof (city); memset (link, 0, sizeof (Link); IP = 0; M = 0;/* read in the maps */CIN> H> W; int I, j; char temp; for (I = 1; I <= H; I ++) for (j = 1; j <= W; j ++) {CIN> temp; if (temp = '*') ipmap [I] [J] = ++ IP;}/* structure the bipartite graphs */for (I = 1; I <= H; I ++) for (j = 1; j <= W; j ++) if (ipmap [I] [J]) for (int K = 0; k <4; k ++) {int x = I + dire_r [k]; int y = J + dire_c [k]; if (ipmap [x] [Y]) City [ipmap [I] [J] [ipmap [x] [Y] = true; // The "split point" operation is "by the way".} // after the construction of the Bipartite Graph is completed, the problem that follows will be handled in the same way as that of poj3041. V1 = v2 = IP; /* augmented track search */search ();/* output */cout <IP-M/2 <Endl; // 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.