#C6708. Minimum Path Cost in a Grid
Minimum Path Cost in a Grid
Minimum Path Cost in a Grid
You are given a grid of integers with m rows and n columns. Your task is to find the minimum cost to move from the top-left cell to the bottom-right cell. At each step, you may only move either to the right or down.
The transition equation can be expressed in LaTeX as:
\( dp[i][j] = \min(dp[i-1][j],\; dp[i][j-1]) + grid[i][j] \)
where \( dp[i][j] \) is the minimum cost to reach cell \( (i, j) \) and the boundary conditions are given by summing along the first row and first column.
inputFormat
The first line of input contains two integers m and n representing the number of rows and columns in the grid respectively.
This is followed by m lines, each containing n integers separated by spaces; each integer represents the cost of a cell in the grid.
outputFormat
Output a single integer — the minimum cost to reach the bottom-right cell from the top-left cell.
## sample3 3
1 3 1
1 5 1
4 2 1
7