Skip to content

Instantly share code, notes, and snippets.

@brennacodes
Created September 4, 2023 14:56
Show Gist options
  • Save brennacodes/ff0c4969158ba346d0877b0593ffcf35 to your computer and use it in GitHub Desktop.
Save brennacodes/ff0c4969158ba346d0877b0593ffcf35 to your computer and use it in GitHub Desktop.
DP Roadmap

The Ultimate Dynamic Programming Roadmap

Group 1 (warmup):

Basic questions to get a feel of DP.

Group 2 (linear sequence, linear time, constant transition):

Dp solution requires us to solve the sub problem on every prefix of the array. A prefix of the array is a subarray from 0 to i for some i.

Group 3 (on grids):

Dp table will have the same dimensions as grid, the state at cell i,j will be related to the grid at cell i,j.

Group 4 (two sequences, O(NM) style):

Dp[i][j] is some value related to the problem solved on prefix of sequence 1 with length i, and prefix on sequence 2 with length j.

Group 5 (Interval dp):

Dp problem is solved on every single interval (subarray) of the array

Group 6 (linear sequence transition like N^2 Longest Increasing Subsequence)

Dp problem is solved on every prefix of the array. Transition is from every index j < i.

Group 7 (knapsack-like)

Dp state is similar to the classical knapsack problem.

Group 8 (topological sort with graphs. advanced, optional)

Solve dp on all subgraphs that are connected to each node

Group 9 (dp on trees. advanced, optional)

Solve dp problem on all subtrees.

Also get the list here: https://algo.monster/dp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment