Skip to content

Cheapest Way Across

Each cell of an m by n grid charges a toll. Starting at the top-left cell and moving only right or down, print the smallest total toll paid on the way to the bottom-right cell, counting both the first cell and the last.

This is the previous problem with two changes and no others. The two predecessors are combined with a minimum instead of a sum, because they are now alternatives to choose between rather than possibilities to total. And the cell's own toll is added, because a route's price is the sum of what it steps on.

The edges change meaning with it: the top row is no longer all ones but the running total along that row.

Constraints - `1 ≤ m ≤ 200` - `1 ≤ n ≤ 200` - `0 ≤ toll ≤ 1000`