#P14710. [ICPC 2023 Tehran R] Star Wars

[ICPC 2023 Tehran R] Star Wars

题目描述

Amirreza is playing the Star Wars game. This game is played on an n×mn \times m board where each cell is either empty ('..'), contains a white piece ('WW') or a black piece ('BB'). At start of the game, Amirreza should choose exactly one white piece to play with. Afterwards he can move this piece multiple times to knock out as many black pieces as possible. Suppose the white piece is currently in cell (i,j)(i, j) of the board; In one move, this piece can go up-left (i1,j1)(i - 1, j - 1), up (i1,j)(i - 1, j) or up-right (i1,j+1)(i - 1, j + 1), provided that cell exists on the board and it does not contain another white piece. If the cell contains a black piece, it will be knocked out. Help Amirreza figure out the maximum number of black pieces he can knock out.

输入格式

The first line contains two integers nn and mm (1n,m501 \leq n, m \leq 50), the number of rows and columns in the board, respectively. This is followed by nn lines, each containing mm characters. The jthj^{th} character of the (i+1)th(i + 1)^{th} line represents cell (i,j)(i, j). Each character is 'WW', 'BB', or '..', denoting a white piece, a black piece, or an empty cell, respectively.

输出格式

Print a single integer, the maximum number of black pieces Amirreza can knock out.

8 10
.W...BB...
W..B.WB...
.B.WB...W.
.B..B.....
..W...BB..
B.B..B.W.W
.WB.W...B.
..W..BW.B.
5