Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
How many ways can the six numbers [1, 2, 3, 4, 5, 6] be assigned to three labelled groups (group A, group B, group C), each number going to exactly one group, so that all three groups have the same sum? Empty groups are not allowed.
- A. 3
- B. 12
- C. 27
- D. 6
Correct answer: D. 6
The three sums must each equal total/3 = 7. Count labelled assignments with a bitmask DP over which numbers are in group A and group B; halving the count assumes a symmetry that the labels break.
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
- From the numbers [1, 2, 3, 5, 6, 8, 9, 10], what is the size of the largest subset in which any two chosen numbers differ by at least 2?
- Starting at index 0 of the array [4, 8, 5, 2, 25], repeatedly jump to the next strictly greater element (a monotonic stack gives these…
- What is the sum of the stock span values for prices [100, 80, 60, 70, 60, 75, 85]? The span of day i is the number of consecutive days…
- A queue is built from two stacks: enqueue pushes onto the inbox stack, and dequeue pops from the outbox stack, first transferring all…
- How many non-empty distinct palindromic partitions, i.e. ways to split the string aabb into contiguous pieces where every piece is a…
- How many distinct non-empty subsequences (as strings) does the word aba have?