From violent recursion to advanced dynamic programming

"Starting from 0 to make LeetCode" advanced from violent recursion to dynamic programming

1. Number of ways to exchange money

Insert picture description here
Violent recursion:

Insert picture description hereAlways let you calculate the repeated state multiple times

No aftereffects

Queen N-there is a problem of aftereffect-basically not tested

Brute force method optimization: take a map record

Memory search:

Insert picture description here
Change to dynamic programming:

Insert picture description here
Optimization of space

Insert picture description here
2. Solitaire game problem in a line

Insert picture description here

Violent recursion

Insert picture description here
Dynamic programming, two tables
Insert picture description here

3. Walking problems

Insert picture description here
Change dynamic programming:
a bit similar to Yanghui triangle.
Find the value of M and P step: the
variables are also K and P, according to which the initial value can be determined
Insert picture description here

Guess you like

Origin blog.csdn.net/bosszhao20190517/article/details/108010599