minimum path sum

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]