Data Structures & AlgorithmsVery hard

Why does the count of subsequences (index subsets) with sum divisible by m use a DP over residues rather than enumerating subsets?

  1. A. Subsets can only be counted by listing them.
  2. B. Residues are always equal to the sum.
  3. C. The DP over m residues runs in O(n·m) time and counts subsets without listing each one, which is needed when n is large.
  4. D. The DP needs m to be larger than n.

Correct answer: C. The DP over m residues runs in O(n·m) time and counts subsets without listing each one, which is needed when n is large.

Each item either joins or stays out, updating how many subsets reach each residue, so the table has n·m steps. Listing 2^n subsets is only feasible for small n.

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

Exams that ask this topic