Dynamic programming - cocoder39/coco39_LC GitHub Wiki

How to identify a DP problem:

  1. optimal solution of a problem is constructed based on optimal solution of subproblems (same property as greedy)
  2. subproblems overlap: subproblems used to construct one problem may also be used to construct another problem

recursion + memo: Compared with DP, recursion is sometimes straightforward. With DP, you may get opportunity to reduce memory usage

problem

  • min/max value
  • valid/invalid
  • valid solutions

core:

word break

enumeration

recursion

range sum

max subarray

stock

longest increasing sequence

Misc

2D

string match

matrix

1d to 2d

3D

string

Minimax

Knapsack Problem

Jump Game (dp or greedy kinda of like BFS)

左右双向dp