Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

A 1 × 11 strip must be covered exactly by tiles of lengths 2, 3 and 5 (tiles cannot overlap or stick out). Tile lengths 2, 3, 5 cost 4, 5 and 9 respectively. What is the minimum total cost, or −1 if impossible?

  1. A. -1
  2. B. 19
  3. C. 22
  4. D. 20

Correct answer: B. 19

Unbounded DP over lengths: d[i] = min over tile length L ≤ i of d[i − L] + cost(L), with d = ∞ when a length cannot be covered. Greedy largest-tile-first fails here: 5 + 5 leaves one cell that no tile can cover, so the exact cover needs the DP.

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

Exams that ask this topic