Data Structures & AlgorithmsVery hard

Why does the count of subsequences with sum divisible by m give the same answer if you replace each value by its residue mod m?

  1. A. The answer always becomes zero.
  2. B. Residues change the set of subsets.
  3. C. Residues are only valid for prime m.
  4. D. Subset sums depend only on residues, since (a + m) and a have the same residue, so the divisibility test is unchanged.

Correct answer: D. Subset sums depend only on residues, since (a + m) and a have the same residue, so the divisibility test is unchanged.

Divisibility by m depends only on the total mod m, so each value can be reduced first without changing which subsets qualify. This is the reason residue DPs are valid.

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

Exams that ask this topic