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?
- A. Subsets can only be counted by listing them.
- B. Residues are always equal to the sum.
- 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.
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Why is an XOR-zero subset family structured like a vector space over the two-element field?
- When counting subarrays with sum in a range [L, R] for an array with zeros, why can a single subarray start be counted many times with a…
- Why does the lexicographically smallest arrangement with a 'no fixed point' constraint start with the value 2?
- When enumerating subsets, what is the total count of non-empty subsets of an n-element set?
- 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?
- Which statement about the prefix product Pi and suffix product Si modulo a prime p is correct when a zero element is present?