##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You know the 0/1 knapsack pattern. Now apply it to harder variants like Tallest Billboard, where constraints and state design push beyond textbook examples.
Why this family matters
Constraints that scream knapsack
Binary choices, additive limits
LC 956 - equal height supports
Track difference, not both
Difference as the state dimension
Skip, add left, or add right
Both supports empty at start
Hash map for sparse states
Why S not S² in the bound
One dimension beats two
CF 687C - subset of a subset
Track two sums at once
dp[total][partial] = reachable?
Include in total, partial, or skip
dp[0][0] = true, rest false
Reverse iteration avoids reuse
Quadratic in target value
Nested subset constraints
LC 879 - the gang problem
Counting vs optimizing
Cap profit to bound states
+= instead of max()
3D logic in 2D space
Counting with multiple constraints
CF 837D - maximize trailing zeros
Zeros come from min(2s, 5s)
Fix 5s, greedily pick 2s
Knapsack over factor counts
Precompute 2s and 5s
Optimize one, iterate the other
CF 864E - deadlines and values
Sort by deadline first
Time as the knapsack capacity
Must finish before deadline
Reconstruction with backtracking
Scheduling reduces to knapsack
1D array suffices
Why backward for 0/1 knapsack
Each item has a copy limit
Which items made the optimal?
Backtrack through the DP table
Is this knapsack?
Zero capacity, empty arrays
Forward vs backward iteration
LC 2585
Solution approach
CSES 1093
Solution approach
LC 2742
Solution approach
LC 2518
Solution approach
CSES 1628
Solution approach
From 0/1 to bounded to unbounded