Codeforces Beta Round 87 (Div. 2 Only)
B
Little Pigs and Wolves
Codeforces
1100
原题
← AC →
翻译中…

Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size $*n* × *m*$. Each cell in this grid was either empty, containing one little pig, or containing one wolf.

翻译中…

A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs.

翻译中…

They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf.

翻译中…

What is the maximum number of little pigs that may be eaten by the wolves?

翻译中…

Input

翻译中…

The first line contains integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 10$) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow $*n*$ lines containing $*m*$ characters each — that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf.

翻译中…

It is guaranteed that there will be at most one wolf adjacent to any little pig.

翻译中…

Output

翻译中…

Print a single number — the maximal number of little pigs that may be eaten by the wolves.

翻译中…

Note

翻译中…

In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows.

翻译中…

image

翻译中…

样例

Input #1
2 3
PPW
W.P
Output #1
2
InputCopy OutputCopy
Input #2
3 3
P.W
.P.
W.P
Output #2
0
InputCopy OutputCopy
题目信息
题号
116B
时间限制
2 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。