Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 36s1 days 16 hours 1 minutes 36 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 36s1 days 16 hours 1 minutes 36 seconds.

Sign in to watch this lesson
Advanced - Number Theory · 4:39
The loop s = (s - 1) & m walks every submask of a bitmask m from the largest down, at two operations per step, because the allowed bits behave like a small counter being decremented. We handle the empty submask safely, prove that looping over all masks and all their submasks costs 3ⁿ rather than 4ⁿ, and use it for the classic dynamic program that splits a set into the best teams.