#C11184. Minimum Cost Path in a Grid
Minimum Cost Path in a Grid
Minimum Cost Path in a Grid
You are given a 2D grid of non-negative integers. Each cell in the grid represents the cost of stepping on that cell. Your task is to compute the minimum cost required to travel from the top-left corner (cell (1,1)) to the bottom-right corner (cell (m,n)).
You can only move either right or down at any step.
For example, given the grid \[ \begin{matrix} 1 & 3 & 1 \\ 1 & 5 & 1 \\ 4 & 2 & 1 \end{matrix} \] The minimum cost path is: 1 \(\to\) 3 \(\to\) 1 \(\to\) 1 \(\to\) 1, with a total cost of 7.
inputFormat
The first line of input contains two integers m and n — the number of rows and columns in the grid, respectively.
This is followed by m lines, each containing n space-separated integers representing the grid's rows.
Note: All values in the grid are non-negative integers.
outputFormat
Output a single integer — the minimum cost required to reach the bottom-right corner of the grid from the top-left corner.
## sample2 2
1 2
3 4
7
</p>