Dsa
Dynamic Programming
Easy
City Road Construction
In a city, there are several blocks, each separated by roads. You have to allocate workers to repair these roads, and each road has a repair cost associated with it. The workers can only repair a road if they have already repaired all adjacent roads leading to that road. Given the list of roads with repair costs, find the minimum total cost required to repair all roads such that each road can be repaired considering the constraints.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 100), the number of roads.
- The second line contains n integers representing the repair costs of each road.
Output format:
- Output a single integer, the minimum total repair cost.
Example:
Input:
4
3 2 4 1
Output:
6
Key concepts
dynamic_programminggraphpathfinding
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now