Dsa
Dynamic Programming
Medium
Best Road Trip Route
You are planning a road trip that goes through a series of cities, each with a specified distance to travel to the next city. Your trip begins at city 0 and ends at city n-1, and you can stop at each city along the way. However, you can take a rest stop every 'k' cities, and there is a limited number of times you can stop for rest (up to 'r' times). Calculate the minimal distance you need to travel to reach your destination while adhering to the constraints.
Input format:
- The first line contains integers n (number of cities) and r (maximum rest stops).
- The second line contains n-1 space-separated integers (distances between cities).
- The third line contains an integer k (rest stop interval).
Output format:
- A single integer representing the minimal distance.
Example:
Input:
5 2
10 20 30 5
2
Output:
50
Key concepts
dynamic_programminggraph
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