Skip to main content

Potion Mixing

Challenge on lesson: Checkpoint — Dynamic Programming

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** A potion recipe is a sequence of n steps; step i takes t[i] minutes and must be preceded by every step it depends on. Dependency j < i is given as a 0/1 matrix: cell (i, j) = 1 means step i requires step j finished first. Compute the minimum time to finish all steps if independent steps run in parallel. **Input:** Line 1: n (1 <= n <= 100). Line 2: n times t[i] (1 <= t[i] <= 1000). Next n lines: n characters each, '0' or '1' — row i, column j (1-based rows; diagonal is '0'; the matrix is guaranteed acyclic). **Output:** One integer — the minimum total minutes. **Example:** 3 / 2 3 4 / 000 / 100 / 110 -> 9: step 1 done at 2, step 2 (needs 1) done at 5, step 3 (needs 1 and 2) done at max(2,5)+4 = 9.

Back to lesson: Checkpoint — Dynamic Programming