EIUGAME - Maximum path sum
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Given a matrix of ~n~ rows and ~m~ columns numbered from top to bottom, left to right, each cell in the matrix is a random number whose absolute value does not exceed ~10^9~. From the upper left position, find a path to the lower right corner position so that the number of squares to go through is minimal (each move only goes to the square with a common edge). Among those ways, find a way to maximize the sum of the values of the cells on the path.
Input
- The first line is ~2~ integers ~n~, ~m~ (~n~, ~m \leq 2\times10^3~).
- The ~i^{th}~ line of the next ~n~ lines contains ~m~ space-separated integers. The ~j^{th}~ value in line ~i~ corresponds to the ~a_{i,j}~ value in the matrix(~|a_{i,j}| \leq 10^9~).
Output
- A single integer that is the maximum sum along the path found.
Example Input 1
3 3
1 2 3
-1 5 6
0 2 9
Example Output 1
23
Bình luận