eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Drop Zone

Drop Zone

Лимит времени 1 секунда
Лимит использования памяти 64 MiB

Evacuation missions and supply gathering missions are conducted on a regular basis by special teams. One of the first objectives of these missions is to set up a perimeter with barricades. Barricades are costly and take time to set up, so it is important to reduce the number of barricades necessary to block off an area.

You will be provided with several maps of high-interest drop zones. It is your job to write a program that will output the minimum number of barricades required for each drop zone.

Zombies will begin their approach from outside the map, thus any open area on the border is accessible to zombies. Barricades can be placed between any two adjacent open areas (including the drop zone) to block zombie movement. All zones outside of the map should be considered open areas.

Here is an example of one of the maps you will be provided:

XXX..XXX

XXX..XXX

.....XXX

XXX..XXX

XDDDD.XX

XDDDD...

XXXXXXXX

Legend:

Example barricade configuration:

Solution: 3

Входные данные

The first number, N (1N20), will be the number of maps. For each map, there will be two parameters, R and C (1R, C150), denoting the number of rows and columns in the map, followed by the map itself as described above. Each row will be on its own line and all rows will have the same number of characters equal to C.

Выходные данные

For each map, print a single line containing the minimum number of barricades required to block off the drop zone.

Пример

Входные данные #1
2
7 8
XXX..XXX
XXX..XXX
.....XXX
XXX..XXX
XDDDD.XX
XDDDD...
XXXXXXXX5 5
XX.XX
.DDD.
XD.DX
X....
X....
Выходные данные #1
3
6
Источник ACM ICPC South Central USA Regional Programming Contest 2013