#C14039. Minimum Path Sum in a Grid
Minimum Path Sum in a Grid
Minimum Path Sum in a Grid
You are given an \(m \times n\) grid containing non-negative integers. Your task is to compute the minimum sum of a path from the top-left corner to the bottom-right corner. You can only move either down or right at any point in time.
In addition to the minimum sum, you must also report the path as a sequence of coordinates in the format (i,j)
, where i
is the row index and j
is the column index. The path should represent the order in which the cells are visited.
Constraints:
- \(1 \leq m, n \leq 100\)
- All grid numbers are non-negative integers.
Consider using dynamic programming to design an efficient solution.
inputFormat
The first line contains two space-separated integers \(m\) and \(n\), representing the number of rows and columns of the grid. Each of the next \(m\) lines contains \(n\) space-separated non-negative integers representing the grid.
outputFormat
Output the minimum path sum on the first line. On the second line, output the sequence of grid coordinates along the path from the top-left to the bottom-right, formatted as (i,j)
and separated by spaces.
3 3
1 3 1
1 5 1
4 2 1
7
(0,0) (0,1) (0,2) (1,2) (2,2)
</p>