Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

Two players alternately take a pile from either END of the row [4, 15, 3, 9, 2, 8]; the first player moves first and each takes the whole pile they choose. Both play optimally to maximise their own total. What is the maximum total the FIRST player can guarantee?

  1. A. 20
  2. B. 35
  3. C. 33
  4. D. 32

Correct answer: D. 32

Interval game DP: f(i, j) = max over taking a[i] or a[j] of (the pile + the minimum of what the opponent can force on the remaining range). Greedy by taking the larger visible end is a trap, since it can leave the opponent a stronger position.

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

Exams that ask this topic