2403: Harvest Waterloo

Memory Limit:128 MB Time Limit:1.000 S
Creator:
Submit:34 Solved:4

Description

There is a wildly popular new harvest simulation game called Harvest Waterloo. The game is played on a rectangular pumpkin patch which contains bales of hay and pumpkins of different sizes. To begin the game, a farmer is placed at the location of a pumpkin. 
The farmer harvests all pumpkins they can reach by moving left, right, up, and down throughout the patch. The farmer cannot move diagonally. The farmer can also not move through a bale of hay nor move outside of the patch. 
Your job is to determine the total value of all the pumpkins harvested by the farmer. A small pumpkin is worth 1, a medium pumpkin is worth 5, and a large pumpkin is worth 10 dollars. 
有一个非常受欢迎的新游戏叫做《Harvest Waterloo》。这个游戏在一个长方形的南瓜地里进行,地里面有干草捆和不同大小的南瓜。游戏开始时,一位农民会放在一个南瓜的位置上。 
农民可以通过上、下、左、右移动来收割所有他能到达的南瓜。农民不能斜向移动,也不能穿过干草捆或者走出南瓜地。 
你的任务是计算农民收割所有南瓜的总价值。小南瓜价值 1,中南瓜价值 5,大南瓜价值 10。

Input

The first line of input is an integer R > 0 which is the number of rows within the patch. The second line of input is an integer C > 0 which is the number of columns within the patch. The next R lines describe the patch. 
Each line will contain C characters and each character will either represent a pumpkin size or a bale of hay: S for a small pumpkin, M for a medium pumpkin, L for a large pumpkin, or * for a bale of hay. 
The next line of input is an integer A where 0 ≤ A < R, and the last line of input is an integer B where 0 ≤ B < C. Row A and column B is the starting location of the farmer and the top-left corner of the patch is row 0 and column 0. 
第一行输入是一个整数 R > 0,代表南瓜地的行数。 
第二行输入是一个整数 C > 0,代表南瓜地的列数。 
接下来的 R 行描述了南瓜地。每一行包含 C 个字符,每个字符代表一个南瓜的大小或者是干草捆:S 表示小南瓜,M 表示中南瓜,L 表示大南瓜,* 表示干草捆。 
下一行是一个整数 A,其中 0 ≤ A < R,最后一行是一个整数 B,其中 0 ≤ B < C。行 A 和列 B 是农民的起始位置,南瓜地的左上角是行 0 列 0。

Output

Output the integer, V , which is the total value in dollars of all the pumpkins harvested by the farmer.
输出一个整数 V,即农民收割的所有南瓜的总价值(以美元计)。

Sample Input

6
6
**LMLS
S*LMMS
S*SMSM
******
LLM*MS
SSL*SS
5
1

Sample Output

37

HINT



Starting at row 5 and column 1, the farmer can reach the 6 pumpkins in the highlighted area. They harvest 2 small pumpkins, 1 medium pumpkin, and 3 large pumpkins. The total value in dollars of this harvest is 2 × 1 + 1 × 5 + 3 × 10 = 37.

从第5行第1列开始,农民可以到达高亮区域的6个南瓜。他们收割了2个小南瓜,1个中南瓜和3个大南瓜。这次收割的总价值是 2 × 1 + 1 × 5 + 3 × 10 = 37美元。

Source/Category