Data Structures & AlgorithmsVery hardICPC regional · GATE CS
A stick of length 9 must be cut at the positions [5, 1, 7, 3]. A cut costs the current length of the stick piece it splits, and the cuts may be performed in any order. What is the minimum total cost?
- A. 27
- B. 21
- C. 23
- D. 16
Correct answer: B. 21
Add the endpoints 0 and n, then use interval DP: the first cut inside a segment (l, r) costs r − l and splits it into two independent problems. Making the cheapest cut first is a greedy trap.
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
- How many binary strings over the alphabet {a, b} of length 6 contain EXACTLY 2 occurrences of the adjacent pair "ab" (occurrences may not…
- How many binary strings of length 9 contain NO occurrence of the substring 010?
- In how many ways can the integer 10 be written as a sum of AT MOST 3 positive integers, where order does not matter (for example 10 = 7 +…
- From [1, 2, 3, 4, 6, 8, 12, 16, 18, 24, 36], choose the largest subset in which every pair of elements (the smaller divides the larger)…
- What is the largest XOR value obtainable as the XOR of a non-empty contiguous subarray of [8, 1, 2, 12, 7, 6]?
- What is the length of the longest arithmetic subsequence (equal consecutive differences, chosen by index) of [3, 6, 9, 12, 5, 10, 15, 20…