dsa2 min read
Partition Equal Subset Sum — 0/1 Knapsack
Can array be partitioned into two equal-sum subsets? 0/1 knapsack: can we pick some numbers summing to total/2? Bitset or DP boolean array.
Read →
webcoderspeed.com
1276 articles
Can array be partitioned into two equal-sum subsets? 0/1 knapsack: can we pick some numbers summing to total/2? Bitset or DP boolean array.
Assign + or - to each number to reach target sum. DP counts ways to reach each sum. Reduces to 0/1 knapsack subset sum count.
LCS of two strings: dp[i][j] = LCS of first i chars of s1 and first j chars of s2. Full 2D DP treatment in the 2D DP section.
Complete 1D DP cheatsheet: 8 patterns, key transitions, complexity table, and problem index.
Master 2D DP: LCS, Edit Distance, grid path counting, matrix chain, interval DP, and stock patterns with 5-language templates.