/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} 17 E Given an unlimited supply of coi... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

Given an unlimited supply of coins of denominations, we wish to make change for a value ; that is, we wish to find a set of coins whose total value is . This might not be possible: for instance, if the denominations are and 10 then we can make change for 15 but not for 12. Give an dynamic-programming algorithm for the following problem.Input:,; .Question: Is it possible to make change for using coins of denominations ?

Short Answer

Expert verified

The algorithm is as follows:

Create an array of size

D0=Truefori=1â€Ôò´Ç V â¶Ä„â¶Ä„Di=Falseforv=1â€Ôò´Ç V â¶Ä„â¶Ä„forj=1â€Ôò´Ç V

 â¶Ä„â¶Ä„ â¶Ä„â¶Ä„ifxj≤v â¶Ä„â¶Ä„ â¶Ä„â¶Ä„ â¶Ä„â¶Ä„Dv=DvORDv−xi â¶Ä„â¶Ä„ â¶Ä„â¶Ä„else â¶Ä„â¶Ä„ â¶Ä„â¶Ä„ â¶Ä„â¶Ä„Dv=False°ù±ð³Ù³Ü°ù²Ô DV

Step by step solution

01

Define dynamic programming 

Dynamic programming is a paradigm used for writing algorithm which helps to solve some particular type of problems more efficiently by saving the solution of subproblems and using them to get the final solution. Rather than performing the same calculation again and again, the optimal solution to subproblems are calculated and stored.

02

Determine the subproblem

ConsiderDu as sub-problem such that u=1,….,v.

Thus, according to question,Du is true if it is possible to make change for v using coins denomination.x1,x2,…xn

Du=TRUE;ifitispossibletomakechangeforvFALSE;otherwise

Now, takingDu as sub-problem, if it is possible to make change forv using denomination,x1,x2,…xnthen it is also possible to make change for by using same denomination with the coin.

The desired recursion is:

Here, ‘’ is the value for which we finding denomination.

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 91Ó°ÊÓ!

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

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.)

Suppose two teams, A and B, are playing a match to see who is the first to win games (for some particular n). We can suppose that A and B are equally competent, so each has a 50% chance of winning any particular game. Suppose they have already played i+j games, of which A has won i and B has won j. Give an efficient algorithm to compute the probability that A will go on to win the match. For example, if i=n-1 and j=n-3 then the probability that A will win the match is 78, since it must win any of the next three games.

Yuckdonald’s is considering opening a series of restaurant along Quaint Valley Highway(QVH). The n possible locations are along a straight line, and the distances of these locations from the start of QVH are, in miles and in increasing order,m1,m22,....,mn.. The constraints are as follows:

At each location, Yuckdonald may open at most one restaurant. The expected profit from opening a restaurant at location i is given aspi, wherepi>0andi=1,2,…,n.

Any two restaurants should be at least k miles apart, where k is a positive integer.

Give an efficient algorithm to compute the maximum expected total profit subject to the given constraints.

Given two strings x=x1x2···xnand y=y1y2···ym, we wish to find the length of their longest common subsequence, that is, the largest k for which there are indices i1<i2<···<ikand j1<j2<···<jkwith xi1xi2···xik=yj1yj2···yjk. Show how to do this in time 0(mn).

A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes n units of time for a string of length n, regardless of the location of the cut. Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can affect the total running time. For example, if you want to cut a 20-character string at positions 3 and 10, then making the first cut at position 3 incurs a total cost of 20+17=37, while doing position first has a better cost of 20+17=37.

Give a dynamic programming algorithm that, given the locations of m cuts in a string of length , finds the minimum cost of breaking the string into m +1 pieces.

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.