Data Structures & AlgorithmsModerate

Count the NON-EMPTY subsets of the 12 items 3 5 6 7 2 9 4 8 1 10 11 12 (chosen by position) whose sum is divisible by 4.

  1. A. 1023
  2. B. 1024
  3. C. 511
  4. D. 1022

Correct answer: A. 1023

Subset counting by sum residue uses a DP over residues mod 4 where each item either joins a subset or not; the empty subset has residue 0 and must be excluded. Counting residue 2, or restricting to even sizes, answers different questions.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic