Super Plumber
Time limit1sMemory limit128 MB
Find the maximum total coin value on a path from the bottom-left to the bottom-right of a grid where SP moves right, up, or down without revisiting cells.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
You are to write a program for a video game in which Super Plumber (SP) navigates an obstacle course, collecting prizes on his way to rescuing the Princess (TP).
The obstacle course is an by grid. SP starts at the bottom-left corner and makes his way to the Princess in the bottom-right corner. Some cells are occupied by obstacles that SP cannot pass through; other cells hold gold coins valued between $1.00 and $9.00.
The game is a traditional side-scroller, so SP may move only right, up, or down, one cell at a time, always into an adjacent cell that has no obstacle. He can never occupy a cell he has already occupied: once he moves up he cannot move down until he next moves right, and once he moves down he cannot move up until he next moves right. SP collects the coin at every cell he visits. Find the maximum total value of coins SP can collect on a route from the bottom-left corner to the bottom-right corner.
Input
The input contains several test cases. The first line of each test case has two integers and (). The grid follows as lines of characters each:
*marks an obstacle,- a digit
1-9marks a coin of that value, .marks an empty cell.
It is always possible for SP to reach the Princess. A line containing 0 0 follows the last test case and must not be processed.
Output
For each test case, print one line containing the maximum total value of coins SP can collect on a valid route from the bottom-left corner to the bottom-right corner. Because every coin is a whole number of dollars, the answer is an integer; print it with no dollar sign and no decimal part.