SOS DP Hot Sheet¶
Use this page when every mask on the full boolean cube needs an aggregate over:
- all of its submasks
- all of its supersets
- or one witness propagated along the same sweep
Do Not Use When¶
- the state evolves by adding one chosen bit -> Bitmask DP
- the mask is a moving grid frontier -> Broken Profile / Plug DP
- the intended transform is xor/and convolution beyond this starter
- the universe is too large for dense arrays of size
1 << bits
Choose By Signal¶
- need
sum_{submask ⊆ mask}for everymask-> subset zeta sweep - need
sum_{supermask ⊇ mask}for everymask-> superset zeta sweep - need one present submask witness for every
mask-> same subset sweep, but overwrite instead of+ - bitwise condition like
x & y == 0-> usually query the transformed array atfull ^ x
Core Invariants¶
- subset sweep: if
maskhas bitb, fold frommask ^ (1 << b)intomask - superset sweep: if
maskdoes not have bitb, fold frommask | (1 << b)intomask - after processing all bits, every dimension of the boolean cube has been prefix-swept once
- the same loop skeleton works for sums, counts, booleans, and one witness value
- the main modeling step is often converting the original predicate into one subset/superset query, frequently via complement masks
Main Traps¶
- reversing subset and superset directions
- forgetting that
x & y == 0meansy ⊆ full ^ x - treating this as plain
dp[mask]evolution instead of one offline cube sweep - opening this lane when explicit submask enumeration is already enough
Exact Starter Route¶
- exact starter -> sos-dp-zeta.cpp
- flagship rep -> Compatible Numbers
- compare point -> Bitmask DP
- compare point -> Broken Profile / Plug DP
- parent chooser -> DP cheatsheet
Reopen Paths¶
- full lesson -> SOS DP
- broader chooser -> DP cheatsheet
- snippet chooser -> Template Library
- retrieval router -> Build Kit