Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional

How many non-empty subsets of {1, 2, 3, 4, 5, 6, 7} have a bitwise AND of their elements equal to 0?

  1. A. 93
  2. B. 88
  3. C. 37
  4. D. 90

Correct answer: D. 90

For a non-empty subset the AND is zero when every bit position is cleared by some element; a DP over the 3 bit positions with a mask of which bits are still set counts these. The complement 127 - count is a different count, which is the trap.

More Coding Interview Problems questions

Exams that ask this topic