Data Structures & AlgorithmsVery hardCodeforces Div2 D · LeetCode-style

Array [2, 3, 1, 4, 2, 5, 1, 2]: from index i you may jump to any index j with i < j ≤ i + a[i]. Landing on index j costs a[j]. Starting at index 0 you must reach the last index using EXACTLY 3 jumps. What is the minimum total cost (sum of the costs of the landed indices, excluding the start)?

  1. A. 9
  2. B. 7
  3. C. 1000000000
  4. D. 8

Correct answer: B. 7

Layered DP over (index, number of jumps used): d[j][t+1] = min(d[i][t] + a[j]) for i < j ≤ i + a[i]. Ignoring the exact-count requirement lets fewer jumps through, and that is a different value.

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

Exams that ask this topic