Moving
InterviewTime limit1sMemory limit256 MB
Jungyu collects the most candy possible walking from the top-left room to the bottom-right room with right, down, and diagonal moves.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Matrix
- Solved
- No attempts yet
Problem
Jungyu is trapped in a maze of size . The maze is divided into rooms of size , and every room holds some candy. The top left room is and the bottom right room is .
Jungyu is at and wants to reach . When he is at he can move to , , or , and every time he visits a room he can take all of the candy in that room. He cannot leave the maze.
Find the largest number of candies Jungyu can collect on his way to . The candy in the starting room counts as well.
Input
The first line contains the size of the maze, and . ()
Each of the next lines contains numbers. The -th number on the -th line is the number of candies in room , which is at least 0 and at most 100.
Output
Print on the first line the largest number of candies Jungyu can collect on his way to .