| <p> |
| You're a proud boomerang farmer, like your father before you (and his father before him, but quite unlike his grandfather). |
| Your boomerang field can be modelled as a 2D grid of square cells, with <strong>M</strong> rows and <strong>N</strong> columns. |
| Each cell contains a boomerang lying flat on the ground, in one of four possible orientations called A, B, C, and D: |
| </p> |
|
|
| <img src="{{PHOTO_ID:263973168278076}}" /> |
|
|
| <p> |
| For example, your field might look as follows: |
| </p> |
|
|
| <img src="{{PHOTO_ID:572878846700654}}" /> |
|
|
| <p> |
| As you can see, there are 2 points at which pairs of boomerangs are touching one another at their endpoints. |
| As all boomerang farmers know, that could stunt the growth of your precious boomerangs! |
| </p> |
|
|
| <p> |
| Fortunately, you can salvage the situation by rotating boomerangs by integer multiples of 90 degrees. |
| In particular, rotating a single boomerang by 90 degrees either clockwise (for example, changing its orientation from A to B) or counter-clockwise (for example, from A to D) takes 1 minute. |
| You may rotate a single boomerang multiple times. |
| </p> |
|
|
| <p> |
| You have <strong>K</strong> minutes of free time that you can use to fix up your field as well as you can (though you don't have to use all of this time). |
| What's the minimum number of pairs of touching boomerangs that you can end up with at the end of this time? |
| For example, given 2 minutes to work on the above field, you could rotate the top-right boomerang counter-clockwise and the bottom-left one clockwise to end up with no touching boomerangs: |
| </p> |
|
|
| <img src="{{PHOTO_ID:3313736538657036}}" /> |
|
|
|
|
| <h3>Input</h3> |
| <p> |
| Input begins with an integer <strong>T</strong>, the number of fields. |
| For each field, there is first a line containing the space-separated integers <strong>M</strong>, <strong>N</strong>, and <strong>K</strong>. |
| Then, <strong>M</strong> lines follow, the <strong>i</strong>th of which contains a string of length <strong>N</strong> representing the |
| <strong>i</strong>th row of the field as described above. |
| </p> |
|
|
|
|
| <h3>Output</h3> |
| <p> |
| For the <strong>i</strong>th field, print a line containing "Case #<strong>i</strong>: " followed by |
| the minimum number of touching boomerang pairs that will remain after you work the field optimally. |
| </p> |
|
|
|
|
| <h3>Constraints</h3> |
| <p> |
| 1 ≤ <strong>T</strong> ≤ 100 <br /> |
| 1 ≤ <strong>M</strong>, <strong>N</strong> ≤ 100 <br /> |
| 0 ≤ <strong>K</strong> ≤ 1,000 <br /> |
| </p> |
|
|
|
|
| <h3>Explanation of Sample</h3> |
| <p> |
| The fifth field is the example given above. |
| </p> |
|
|
|
|