You are given an grid of squares. Each square contains a number
,
, the cost to travel through that square. You are starting at the most top-left square. At each turn you may choose to move down or right but not both. Find the minimum cost it would take you to travel to the most bottom-right square.
Constraints
In all tests,
Input Specification
The first line contains two integers, and
, the dimensions of the grid of squares (
rows and
columns).
The next lines each contains
integers,
, the cost to travel through that square in the grid.
Output Specification
Output on a single line, the minimum sum of costs to travel from the most top-left square to the most bottom-right square.
Sample Input
3 4
3 1 2 4
9 8 7 6
2 8 9 2
Sample Output
18
Explanation for Sample Output
We can take the path , which gives us the sum of
.
There are no paths that yield a smaller sum.
Comments