#P7074. [CSP-J 2020] 方格取数
[CSP-J 2020] 方格取数
Problem Description
There is an grid, and each cell contains an integer. Now there is a little bear that wants to move from the top-left corner to the bottom-right corner. Each step can only move one cell up, down, or right, and it cannot visit any cell more than once, and it cannot go out of bounds. The bear will take all the integers in the cells it passes through. Find the maximum possible sum of the integers it can take.
Input Format
The first line contains two integers .
In the next lines, each line contains integers, which represent the integer in each cell in order.
Output Format
Output one integer, which is the maximum sum of integers the bear can take.
3 4
1 -1 3 2
2 -1 4 -1
-2 2 -3 -1
9
2 5
-1 -1 -3 -2 -7
-2 -1 -4 -1 -2
-10
Hint
Explanation for Sample 1

Explanation for Sample 2

Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, . The absolute value of the integers in the grid does not exceed .
On 2024/2/4, one set of hack testdata was added.
Translated by ChatGPT 5