Question
Problem 4. Highway Restaurants (25 points) (a) (18 points) You want to open a chain of restaurants along a given highway, which starts at mile
Problem 4. Highway Restaurants (25 points)
(a) (18 points) You want to open a chain of restaurants along a given highway, which starts at mile marker 1 and ends at some mile marker n. Each mile marker is a possible location where you can build a restaurant, and you are given an array P[1 . . . n], where P[i] is the profit you get for building at mile marker i. You can build as many restaurants as you want (and the cost of building is already factored into P[i]), however, any two restaurants you build must be m miles apart so that they do not compete with one another. Using dynamic programming, give an O(n) time algorithm to compute the maximum possible profit you can get from building restaurants.
(b) (7 points) Describe how to modify you solution from part (a) to return a list of the mile markers where you should build your restaurants to get the maximum profit.
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