#K72037. Maximum Score Path in Grid
Maximum Score Path in Grid
Maximum Score Path in Grid
You are given an n x m grid of integers. Your task is to find the maximum score obtainable by moving from the top-left cell to the bottom-right cell. At each step, you are allowed to move only to the right or downward.
The score of a path is defined as the sum of the values of the cells visited. The recurrence relation for the dynamic programming solution is given by:
[ \text{dp}[i,j] = \max(\text{dp}[i-1,j],, \text{dp}[i,j-1]) + A[i,j] ]
where A[i,j]
denotes the value in the cell at the i
-th row and j
-th column (using 0-indexing). It is guaranteed that n
and m
are positive integers, and the grid may contain negative values.
inputFormat
The first line contains two integers n and m, representing the number of rows and columns of the grid respectively. This is followed by n lines, each containing m space-separated integers representing the grid's values.
outputFormat
Output a single integer which is the maximum score achievable from the top-left corner to the bottom-right corner.
## sample3 3
5 3 2
1 2 1
1 1 5
16