Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You have decided to drive from City A to city B and you want to figure out which hotels you should stay at along the
You have decided to drive from City A to city B and you want to figure out which hotels you should stay at along the way. Assume that there is only one highway from City A to City B that is exactly n miles long and that there is exactly one hotel at each mile along this highway. Each day, you can drive at most k miles and then, if you have not reached B you must stop at a hotel for the night. Given the price of staying at each hotel for one night, you want to find the minimum possible total amount of money that you can spend spend on hotel during your trip. Give a dynamic programming based algorithm for this problem. Justify the correctness of your algorithm and find the time complexity. Example: Suppose nk and the costs of the hotels, in order, are note that there are only hotels because after you have driven miles, you have reached City B and do not need a hotel Then the minimum total cost is which can be obtained by staying at the hotels at miles and Note that you only need to return the minimum cost not the hotel IDs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started