ProgrammingVery hard

For the grid w = {{1,3,1},{1,5,1},{4,2,1}}, what is the minimum sum of a path from top-left to bottom-right moving only right or down?

  1. A. 9
  2. B. 3
  3. C. 12
  4. D. 7

Correct answer: D. 7

DP: each cell adds the smaller of the best costs from above and from the left, giving 7 via 1, 3, 1, 1, 1. 9 is the greedy path that always steps to the cheaper neighbour (down into the 4), 3 jumps to the cheapest cell of each row as if moves were free, and 12 is the maximum path.

More C Programming questions

Exams that ask this topic