##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Bitmask DP, digit DP, interval DP, tree DP, and contribution techniques through 10 problems.
What this section covers
The patterns ahead
CF 16E - probability bitmask DP
State is surviving set
Expected value over pairs
Exponential but feasible
CF 580D - satisfaction with bonuses
Track set and last dish
Iterate by population count
Standard bitmask bounds
CF 453B - coprime sequence
Too many combinations
Track used primes
Enumerate candidate values
Large mask but sparse
CF 1070A - digit sum and divisibility
Infinite search space
BFS on remainder and sum
BFS with path reconstruction
Polynomial in d and s
CF 461B - partition into black-rooted subtrees
Exponential edge subsets
DP on subtree state
DFS combining children
CF 1312E - merge equal neighbors
Operation order matters
Two DP tables
Iterate by interval length
Cubic in array size
CF 1398D - maximize rectangle area sum
DP on pairs used
Three nested loops
Product of pair counts
CF 1467D - contribution over all paths
Exponential paths
Count paths through each cell
Build left and right tables
Quadratic in n and k
CF 1238E - arrange letters to minimize cost
Permutation explosion
Precompute transition costs
SOS DP for subset sums
Exponential but tight
CF 1542D - expected sum after deletions
Exponential subsequences
Count survivals per value
DP for each push operation
Quadratic overall
Test your understanding
What you've learned