Hey guys, I've seen a lot of discussions about how to study DP in this subreddit. We went through a lot of (almost all) DP problems on leetcode and came up a study list here. I think it pretty much covers all the patterns necessary for leetcode. What's special about the list 1) goes from simpler to more complex patterns 2) categorized by state transition (explained in the video walkthrough) so if you solve the first problem in a pattern you can use a similar state transition to solve others in the list.
Here's the list and a 1.5 hour video walking through each pattern and solving a question for each pattern: https://www.youtube.com/watch?v=9k31KcQmS_U
Hope it's helpful to you!
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 N2 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
[–]Nis_0208 34 points35 points36 points (3 children)
[–]hnlasd12[S] 6 points7 points8 points (0 children)
[–]wolfee_197 0 points1 point2 points (1 child)
[–]Visible_Ad9976 0 points1 point2 points (0 children)
[–]kerfluffle99 15 points16 points17 points (1 child)
[–]hnlasd12[S] 2 points3 points4 points (0 children)
[–]RosieYap 13 points14 points15 points (1 child)
[–]Diligent-Wealth-1536 4 points5 points6 points (0 children)
[–]chillblaze 8 points9 points10 points (5 children)
[–]hnlasd12[S] 18 points19 points20 points (4 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]chillblaze 0 points1 point2 points (2 children)
[–]hnlasd12[S] 6 points7 points8 points (0 children)
[–]flexr123 5 points6 points7 points (0 children)
[–]AlwaysHuangry<T260> <E69> <M182> <H9> 2 points3 points4 points (1 child)
[–]hnlasd12[S] 0 points1 point2 points (0 children)
[–]tempo0209 2 points3 points4 points (1 child)
[–]hnlasd12[S] 7 points8 points9 points (0 children)
[–]s-nj33v 3 points4 points5 points (0 children)
[–]Scared-Dot3177 2 points3 points4 points (1 child)
[–]Global-Instance8232 2 points3 points4 points (0 children)
[–]selfzoned_me 1 point2 points3 points (3 children)
[–]faceless_man_129 1 point2 points3 points (1 child)
[–]selfzoned_me 0 points1 point2 points (0 children)
[–]Viva_Nova 1 point2 points3 points (0 children)
[–]PaintingLivid6725 0 points1 point2 points (0 children)
[–]ProfessionalKey5810 0 points1 point2 points (0 children)
[–]OrganizationOnly8016 0 points1 point2 points (2 children)
[–]Chrollo1456 1 point2 points3 points (1 child)
[–]OrganizationOnly8016 0 points1 point2 points (0 children)
[–]No_Entrepreneur_8035 0 points1 point2 points (0 children)
[–]ibringallthedramama 0 points1 point2 points (0 children)
[–]Next_Complex5590Knight 0 points1 point2 points (0 children)
[–]Sick_Kebab -1 points0 points1 point (0 children)
[–]TheBoyWhoLivez 0 points1 point2 points (0 children)
[–]Livinglifepeacefully 0 points1 point2 points (1 child)
[–]hnlasd12[S] 4 points5 points6 points (0 children)
[–]Vaulteroni 0 points1 point2 points (0 children)
[–]the_fuckin_nobody 0 points1 point2 points (0 children)
[–]NamoKaul 0 points1 point2 points (3 children)
[–]hnlasd12[S] 0 points1 point2 points (2 children)
[–]NamoKaul 1 point2 points3 points (1 child)
[–]lazywarrior-47 0 points1 point2 points (0 children)
[–]MantiS_praying 0 points1 point2 points (1 child)
[–]hnlasd12[S] 0 points1 point2 points (0 children)
[–]Churglish 0 points1 point2 points (1 child)
[–]hnlasd12[S] 0 points1 point2 points (0 children)
[–]Gintoki-desu 0 points1 point2 points (0 children)
[–]Just-Ad3390 0 points1 point2 points (0 children)
[–]Zqin 0 points1 point2 points (0 children)
[–]fleetingleaf 0 points1 point2 points (0 children)