minimum path sum

来源:互联网 发布:西宁c软件 编辑:程序博客网 时间:2024/06/05 18:05

question:
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.

Note: You can only move either down or right at any point in time.

answer:
这里写图片描述

note that the idea:
left and up are the only choice that every step concern
path_sum[i, j] = min(path_sum[i-1][j], path_sum[i][j-1]) + matrix[m][n]