#C7932. Maximum Flowers Collected
Maximum Flowers Collected
Maximum Flowers Collected
Alice is exploring a mystical meadow represented by an ( n \times m ) grid. Each cell in the grid may contain a digit (representing the number of flowers), a dot (( '.' )) indicating an empty cell, a hash (( '#' )) representing an impassable obstacle, or a letter T (( 'T' )) representing a trap. Starting from any accessible cell (cells that are either a digit or a dot), Alice can move in the four cardinal directions (up, down, left, right) and collect all flowers in the connected region she can reach. Your task is to determine the maximum number of flowers that can be collected from any such connected region in the grid.
Note: Cells marked with ( '#' ) or ( 'T' ) cannot be traversed.
inputFormat
The input is read from standard input. The first line contains two integers ( n ) and ( m ) (the number of rows and columns, respectively). Each of the following ( n ) lines contains ( m ) space-separated characters. Each character is one of the following: a digit (( '0' )–( '9' )) representing the number of flowers, a dot (( '.' )) for an empty cell, a hash (( '#' )) for an obstacle, or a T (( 'T' )) for a trap.
outputFormat
Output a single integer to standard output, representing the maximum number of flowers that can be collected from any connected region of accessible cells.## sample
3 3
. 2 .
3 # T
1 . .
6