Coin Collection
InterviewTime limit1sMemory limit128 MB
A robot walks right or down only from the top-left to the bottom-right of a grid, and we want the most coins it can pick up along the way.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Matrix, Array, Implementation
- Solved
- No attempts yet
Problem
Coins are placed on the cells of an board, with at most one coin per cell. A robot starts at the top-left cell of the board and wants to collect as many coins as possible on its way to the bottom-right cell. On each step the robot may move only one cell to the right or one cell down from its current position. Whenever the robot passes through a cell that contains a coin, it always picks the coin up. Determine the maximum number of coins the robot can collect.
The figure below shows an example board.

Input
The first line contains a positive integer , the number of test sets.
Each test set begins with a line containing two positive integers and (, ), the number of rows and columns of the board. The next lines each contain characters; each character is either X for an empty cell or C for a coin.
Output
For each test set, print on its own line the maximum number of coins the robot can collect.