#CSPJ2020D. 方格取数 (Grid Numbers Picking)
方格取数 (Grid Numbers Picking)
Description
You are given an grid having an integer in each cell of the grid. A little bear wants to walk from the top left corner to the bottom right corner of the grid. In each step, the bear can only move one cell up, down or right. It can't go to a cell that it has already visited earlier, and it can't go out of the boundary of the grid. The bear will calculate the sum of integers in all the squares it walks through. Find the maximum sum of integers it can obtain.
Input Format
The first line contains two integers and .
-th of the next lines contains integers, which represent the integers in the -th row of the grid.
Output Format
Print a single integer denoting the maximum sum of integers the bear can obtain.
3 4
1 -1 3 2
2 -1 4 -1
-2 2 -3 -1
9
Taking the first path in the image below gives a sum of 9, which is the maximum possible. The second path is invalid because the cell in row 2 and column 2 has been visited twice, which is not allowed. The third path is also invalid, because it does not end at the bottom right corner.
2 5
-1 -1 -3 -2 -7
-2 -1 -4 -1 -2
-10
Taking the path shown in the image below gives a sum of -10, which is the maximum possible. Therefore, the maximum value of the sum may also be negative.
Constraints
For of the data, .
For of the data, .
For of the data, .
For of the data, .
The absolute value of each integer in the grid doesn't exceed .
相关
在下列比赛中: