Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

You are going on a long trip. You start on the road at mile post 0. Along the way there aren hotels, at mile posts a1<a2<...<an , where eachai is measured from the starting point. The only places you are allowed to stop are at these hotels, but you can choose which of the hotels you stop at. You must stop at the final hotel (at distance an), which is your destination. You’d ideally like to travel miles a day, but this may not be possible (depending on the spacing of the hotels). If you travel x miles during a day, the penalty for that day is (200x)2. You want to plan your trip so as to minimize the total penalty- that is, the sum, over all travel days, of the daily penalties.Give an efficient algorithm that determines the optimal sequence of hotels at which to stop

Short Answer

Expert verified

Dynamic programming provides an efficient algorithm to determine the optimal sequence of hotels.

Step by step solution

01

Introduction to Dynamic programming

Dynamic programming helps to solve the problems that can be divided into subproblems and the solution of subproblems is used to calculate the optimal solution of the problem. Dynamic programming obtains both local and global optimal solution.

02

Determine the approach for efficient algorithm to find optimal sequence of hotels

The objective of the algorithm is to reduce the penalty.

Consider OPias the minimum total penalty to reach hotel i. Before reaching hotel i, keep the track of all hotelsj which can be used to stay. So, the minimum penalty to reach hoteli is the sum of minimum penalty to reach hotel ‘j’ and the cost of trip fromj toi is 200ajai2.

Thus, OPi=MINOPj+200ajai2.

The base value is OP0=0becausei=0 is the starting point of the trip. Call the function recursively within the loop to get minimum penalty to reach hotel n.

03

Determine the algorithm to find the optimal sequence of hotels

The algorithm to find the optimal sequence of hotels is as follows:

OP0=0fori=0 to n   OPi=MINOPj+200ajai2 for j=0 to i1return OPn

Thus, the algorithm returns the minimum penalty

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

A contiguous subsequence of a list Sis a subsequence made up of consecutive elements of S. For instance, if Sis 5,15,30,10,5,40,10

then15,30,10 is a contiguous subsequence but5,15,40 is not. Give a linear-time algorithm for the following task:Input: A list of numbers a1,a2,...,an.

Output: The contiguous subsequence of maximum sum (a subsequence of length zero has sum zero).For the preceding example, the answer would be 10,5,40,10, with a sum of 55. (Hint: For each j{1,2,...,n}, consider contiguous subsequences ending exactly at position j.)

The garage sale problem (courtesy of Professor Lofti Zadeh). On a given Sunday morning, there are n garage sales going on, g1,g2,g3............gn. For each garage sale gj, you have an estimate of its value to you, vj. For any two garage sales you have an estimate of the transportation cost dijof getting from gito gj. You are also given the costs d0jand dj0of going between your home and each garage sale. You want to find a tour of a subset of the given garage sales, starting and ending at home, that maximizes your total benefit minus your total transportation costs. Give an algorithm that solves this problem in time O(n22n).

(Hint: This is closely related to the traveling salesman problem.)

Let us define a multiplication operation on three symbols a,b,caccording to the following table; thus ab=b,ba=c, and so on. Notice that the multiplication operation defined by the table is neither associative nor commutative.

Find an efficient algorithm that examines a string of these symbols, say bbbbac, and decides whether or not it is possible to parenthesize the string in such a way that the value of the resulting expression is . For example, on input bbbbacyour algorithm should return yes because((b(bb))(ba))c=a.

Here is yet another variation on the change-making problem (Exercise 6.17). Given an unlimited supply of coins of denominations x1,x2,x3.........xnwe wish to make change for a value v using at most k coins; that is, we wish to find a set ofkcoins whose total value is v. This might not be possible: for instance, if the denominations are 5 and 10 and k=6, then we can make change for 55 but not for 65. Give an efficient dynamic-programming algorithm for the following problem. Input: ; x1,x2,x3.........xn;k;v.Question: Is it possible to make change for v using at most k coins, of denominations x1,x2,x3.........xn?

Consider the following 3-PARTITION problem. Given integersa1,...,an, we want to determine whether it is possible to partition of {1,...,n} into three disjoint subsets I,J,Ksuch that

aiiI=ajjJ=akkk=13aii1 .

For example, for input(1,2,3,4,4,5,8) the answer is yes, because there is the partition(1,8),(4,5),(2,3,4). On the other hand, for input(2,2,3,5) the answer is no. Devise and analyze a dynamic programming algorithm3-PARTITION for that runs in time polynomial in n and in Σiai.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free