How to invent a DP
1) Define what dp[i] means in one sentence. 2) Relate it to smaller states. 3) Fill base cases. 4) Iterate in dependency order.
Lesson
Optimal substructure + overlapping subproblems → tabulated answers.
Loading solution…
1) Define what dp[i] means in one sentence. 2) Relate it to smaller states. 3) Fill base cases. 4) Iterate in dependency order.
Climbing Stairs shows 1D transitions lighting previous two cells.
Linear DP, grid DP, knapsack/subset, string DP (LCS/edit), tree DP, interval DP.
Showing 24 of the related problems in the 1000-question bank.
Longest Palindromic Substring
DP / Expand
Regular Expression Matching
DP
Longest Valid Parentheses
Stack / DP
Wildcard Matching
DP
Jump Game II
Greedy
Maximum Subarray
Kadane / DP
Jump Game
Greedy
Unique Paths
DP
Unique Paths II
DP
Minimum Path Sum
DP
Climbing Stairs
DP
Edit Distance
DP
Maximal Rectangle
Stack / DP
Decode Ways
DP
Unique Binary Search Trees
DP
Best Time to Buy and Sell Stock
DP / Greedy
Best Time to Buy and Sell Stock II
Greedy
Binary Tree Maximum Path Sum
Tree DP
Palindrome Partitioning
Backtracking
Word Break
DP
Maximum Product Subarray
DP
House Robber
DP
House Robber II
DP
Longest Increasing Subsequence
DP / Patience
Got the lesson?
Mark Dynamic Programming as understood when the ideas stick.