本文最后更新于 210 天前,如有失效请评论区留言。
二进制枚举,在处理在n个选numSelect个1的情况,适合用Gosper’s Hack
subset = (1 << numSelect) - 1#起始位置
while subset<...:
lb = subset & -subset#lower bound
left = ((subset ^ x) // lb >> 2)
right = subset + lb
subset = left | right
...
例题:https://leetcode.cn/problems/maximum-rows-covered-by-columns/description/
和状压dp的题:
https://leetcode.cn/problems/minimum-incompatibility/description/
https://leetcode.cn/problems/parallel-courses-ii/description/