#C4252. Minimum Security Cameras
Minimum Security Cameras
Minimum Security Cameras
You are given one or more grids representing building floor plans. Each grid cell is either:
V
: a valuable resource that must be monitored,#
: an obstacle, or.
: an empty space.
A security camera when installed can monitor an entire row or an entire column. Your task is to determine the minimum number of security cameras needed to ensure that every cell containing a valuable resource is monitored by at least one camera.
Note: Installing a camera on a row will monitor all valuables in that row, and similarly for a column. Cameras cannot be placed on individual cells—they cover the entire row or column.
inputFormat
The input is given from standard input in the following format:
T n1 m1 grid_row_1 grid_row_2 ... grid_row_n1 n2 m2 grid_row_1 ... grid_row_n2 ...
Here, T
is the number of test cases. For each test case, the first line contains two integers n
and m
representing the number of rows and columns in the grid. This is followed by n
lines each containing a string of length m
that represents a row of the grid.
outputFormat
For each test case, output a single integer on a new line: the minimum number of security cameras required to monitor all valuable resources.
## sample3
3 3
.V.
.#.
...
4 4
V#.V
.#..
....
.V..
2 2
..
..
1
2
0
</p>