#T706. 【CSP2020-J4】方格取数

【CSP2020-J4】方格取数

Description

There is an n×mn \times m grid, where each cell contains an integer. A little bear starts from the top-left corner of the grid and wants to reach the bottom-right corner. At each step, the bear can move up, down, or right by one cell. The bear cannot revisit any cell it has already passed through, nor can it move outside the grid boundaries. The bear collects the integers from all the cells it traverses. Determine the maximum sum of integers the bear can collect.

Input Format

The first line contains two positive integers, nn and mm.
The next nn lines each contain mm integers, representing the integers in each cell of the grid.

Output Format

A single integer, representing the maximum sum of integers the bear can collect.

3 4
1 -1 3 2
2 -1 4 -1 -2 2 -3 -1
9

Source

CSP2020-J4

(Note: This appears to be an abbreviated reference code, possibly for an exam or competition question. Without additional context, the translation maintains the original code format. Common interpretations could be:

  • "CSP" = Computerized Standardized Testing
  • "2020" = Year
  • "J4" = Junior Level/Division 4 or Question 4)

If this refers to a specific exam system like China's "Certified Secure Programmer" or another context, please provide more details for accurate expansion.