Resource Mining
InterviewTime limit2sMemory limit256 MB
A robot walks from the top-left to the bottom-right cell of an N by M grid using only right and down moves; find the largest number of resource cells it can pass through.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Matrix, Greedy, Implementation
- Solved
- No attempts yet
Problem
WOOK is a next-generation AI robot that mines resources in place of humans. WOOK always stays inside a fixed area. It starts at the top-left cell and explores for resources on its way to the bottom-right cell .
In one move, WOOK can go one cell to the right or one cell down. It cannot move in any other direction. WOOK can collect a resource only when the cell it is standing on holds one. The start and end cells count as well.
Given the map of the area, find the maximum number of resources WOOK can collect.
Input
The first line contains the height and the width of the area ().
Each of the next lines contains space-separated numbers describing the area. A cell with a resource is 1, and empty ground is 0.
Output
Print the maximum number of resources WOOK can collect.