leetcode 64(Mini Path Sum): 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.
the first thought is to build a tree:
1
/ \
1 3
/ \ / \
4 5 1 5
/ /\ / /\
2 1 2 1 1 2
while this is not a balanced tree, no regular tree way to maintain. Then what else solution? Dynamic Programming is a strategy to solve a simple problem at first, then find the rules(status transfer from previous state to current state) for the remaining problems.
step1: the simpler problem, or as initial/boundary condition. e.g. only one row, or only one col, what’s the solution.
step2: in general m rows, n cols, how to get the iterative rules after step1.
|
|
See DP solution is much clear than design the tree.