# (Minimum path overlay) POJ 3020

Source: Internet
Author: User

J-antenna PlacementTime limit:1000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U SubmitStatusPracticePOJ 3020

Description

The Global aerial Centre have been allotted the task of building the fifth generation of mobile phone nets in swed En. The most striking reason so they got the job, is their discovery of a new, highly noise resistant, antenna. It's called 4DAir, and comes in four types. Each type can is transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and Longitudin Al 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 a example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ell Ipses covering them.

Obviously, it is desirable to use as few antennas as possible, but still provide coverages for each place of interest. We model The problem as follows:let A is a rectangular matrix describing the surface of Sweden, where an entry of a eithe R is a point of interest, which must are covered by at least one antenna, or empty space. Antennas can only is positioned at the entry in A. When an antenna was placed at row R and column C, this entry was considered covered, but also one of the neighbouring Entrie S (c+1,r), (c,r+1), (C-1,r), or (C,R-1), is covered depending on the type chosen for this particular antenna. What's the least number of antennas for which there exists a placement in a such so all points of interest are covered?

Input

The first row of input is a single positive an integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing the positive integers h and W, with 1 <= h <= 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 CH Aracters 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

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

Sample Output

`175is to find the minimum path coverage. The key is to build the map.`
`#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <algorithm> #include <cstdlib> #include <queue> #include <vector> #include < Stack>using namespace Std;int h,w,g[45][15],mp[450][450],temp,mark[450],link[450];char c;bool dfs (int x) {for (int i            =1;i<=temp;i++) {if (Mark[i]==-1&&mp[x][i]) {mark[i]=1; if (link[i]==-1| |                DFS (Link[i])) {link[i]=x;            return true; }}} return false;}    int main () {int TT;    scanf ("%d", &AMP;TT);        while (tt--) {temp=0;        int ans=0;        scanf ("%d%d", &h,&w);        memset (link,-1,sizeof (link));        memset (G,0,sizeof (g));        Memset (Mp,0,sizeof (MP));                for (int i=1;i<=h;i++) {for (int j=1;j<=w;j++) {cin>>c;  if (c== ' * ') g[i][j]=++temp;          }} for (int i=1;i<=h;i++) {for (int j=1;j<=w;j++) { if (g[i][j]!=0) {if (i>1&&g[i-1][j]!=0) mp[g[i][j]]                    [G[i-1][j]]=1;                    if (i　　(Minimum path overlay) POJ 3020`
Related Keywords:

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.