You are given a 2D board where in some cells there are gold. You want to fill the board with 2 x 1 dominoes such that all gold are covered. You may use the dominoes vertically or horizontally and the dominoes may overlap. All you have to do is to cover the gold with least number of dominoes.
In the picture, the golden cells denote that the cells contain gold, and the blue ones denote the 2 x 1 dominoes. The dominoes may overlap, as we already said, as shown in the picture. In reality the dominoes will cover the full 2 x 1 cells; we showed small dominoes just to show how to cover the gold with 11 dominoes.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a row containing two integers m (1 ≤ m ≤ 20) and n (1 ≤ n ≤ 20) and m * n > 1. Here m represents the number of rows, and n represents the number of columns. Then there will be m lines, each containing n characters from the set [*, o]
. A *
character symbolizes the cells which contains a gold, whereas an o
character represents empty cells.
Output
For each case, print the case number and the minimum number of dominoes necessary to cover all gold (*
entries) in the given board.
Sample
Sample Input | Sample Output |
---|---|
2 5 8 oo**oooo *oo*ooo* ******oo *o*oo*oo ******oo 3 4 **oo **oo *oo* | Case 1: 11 Case 2: 4 |