def give_change (amount, coins): Given the amount of money, expressed as the total number of kopecks...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
def give_change (amount, coins): Given the amount of money, expressed as the total number of kopecks of Latveria, Ruritania, Mon- tenegro or some other one of those such vaguely Slavic fictional countries that Tintin and similar hearty fellows like to visit for a wacky chase after the current year's MacGuffin, followed by the list of available denominations of coins also expressed as kopecks, this function should create and re- turn a list of coins that add up to the amount using the greedy approach where you use as many of the highest denomination coins when possible before moving on to the next lower denomination. The list of coin denominations is guaranteed to be given in descending sorted order, as should your returned result also be. amount 64 123 100 coins [50, 25, 10, 5, 1] [100, 25, 10, 5, 1] [42, 17, 11, 6, 1] Expected result [50, 10, 1, 1, 1, 1] [100, 10, 10, 1, 1, 1] [42, 42, 11, 1, 1, 1, 1, 1] Along with its countless variations, this problem is a computer science classic when modified to minimize the total number of returned coins. The above greedy approach then no longer produces the optimal result for all possible coin denominations. For example, using the simple coin denomi- nations of [50, 30, 1] and the amount of sixty kopecks to be exchanged, the greedy solution [50, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ends up using eleven coins due to the unfortunate first choice that prevents it from using any of the 30-kopeck coins. Those 30-kopeck coins sure would come handy here, seeing that the optimal solution [30, 30] needs only two such coins! A more advanced recursive algorithm examines both sides of the "take it or leave it" decision for each coin and chooses the choice that ultimately leads to a superior outcome. The intermediate results of this recursion should then be memoized to avoid blowing up the running time exponentially. def give_change (amount, coins): Given the amount of money, expressed as the total number of kopecks of Latveria, Ruritania, Mon- tenegro or some other one of those such vaguely Slavic fictional countries that Tintin and similar hearty fellows like to visit for a wacky chase after the current year's MacGuffin, followed by the list of available denominations of coins also expressed as kopecks, this function should create and re- turn a list of coins that add up to the amount using the greedy approach where you use as many of the highest denomination coins when possible before moving on to the next lower denomination. The list of coin denominations is guaranteed to be given in descending sorted order, as should your returned result also be. amount 64 123 100 coins [50, 25, 10, 5, 1] [100, 25, 10, 5, 1] [42, 17, 11, 6, 1] Expected result [50, 10, 1, 1, 1, 1] [100, 10, 10, 1, 1, 1] [42, 42, 11, 1, 1, 1, 1, 1] Along with its countless variations, this problem is a computer science classic when modified to minimize the total number of returned coins. The above greedy approach then no longer produces the optimal result for all possible coin denominations. For example, using the simple coin denomi- nations of [50, 30, 1] and the amount of sixty kopecks to be exchanged, the greedy solution [50, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ends up using eleven coins due to the unfortunate first choice that prevents it from using any of the 30-kopeck coins. Those 30-kopeck coins sure would come handy here, seeing that the optimal solution [30, 30] needs only two such coins! A more advanced recursive algorithm examines both sides of the "take it or leave it" decision for each coin and chooses the choice that ultimately leads to a superior outcome. The intermediate results of this recursion should then be memoized to avoid blowing up the running time exponentially.
Expert Answer:
Related Book For
Data Analysis and Decision Making
ISBN: 978-0538476126
4th edition
Authors: Christian Albright, Wayne Winston, Christopher Zappe
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
City Place Movie Theaters has four employees and pays them on an hourly basis. During the week beginning June 24 and ending June 30, 2019, these employees worked the hours shown below. Information...
-
A metal ball is dropped into a tall cylinder of oil. The ball initially accelerates but soon reaches a terminal velocity. a. By considering the forces on the metal ball bearing, explain why it first...
-
The tall vertical pump example was successfully brought down to acceptable vibration levels by placing a long 2- 4-inch beam between the top of the motor and a cinder block wall. What else could...
-
Paper Savers Corporation produces wood pulp that is used in making paper. The following data pertain to the company's production of pulp during September: Compute the equivalent units of production...
-
Do you think that people under the age of 18 should be required to wear protective helmets when skateboarding, in-line, bicycling, snowboarding, or skiing? Why or why not.
-
An exercise advocate wants to determine the effect that walking rigorously has on weight loss. The researcher recruits participants to engage in a weeklong study. The researcher instructs...
-
A tunnel AB 75 m long bears S65 degree E on a downward slope of 30 degree. Another tunnel AC is 50 m long and bears N40 degree E on an upward gradient of 1 in 5. If a new tunnel is to be constructed...
-
It is not possible to draw dimensions on an interior elevation view. A) True B) False
-
Fill in the blank field in this text: You use the[1]____________________________ parameter to adjust the vertical position of the roof relative to the current working plane (view).
-
Revit allows you to model bulkheads by adjusting the bottom position of the wall. A) True B) False
-
The RPC components do not cast shadows. A) True B) False
-
Additional Worksets can be created. A) True B) False
-
Situation: Due to the crisis brought by coronavirus-19, the family of Gabriel, who had been living in Metro Manila for so long, will be moing to the province. Gabriel does not agree to his parents'...
-
A superior criticized a sales manager for selling high-revenue, low-profit items instead of lower-revenue but higher-profit items. The sales manager responded, My income is based on commissions that...
-
Referring to the previous problem, you often hear the results of such a poll in the news. In fact, the newscasters usually report something such as, 44.9% of the population approve or strongly...
-
A nuclear power company is deciding whether to build a nuclear power plant at Diablo Canyon or at Roy Rogers City. The cost of building the power plant is $10 million at Diablo and $20 million at Roy...
-
For the completed decision tree in Figure 6.9, the monetary values in black are those you enter. The monetary values in color are calculated automatically by Precision Tree. For this particular...
-
Eliza Perry obtained registration to practice as an aesthetic nurse, and spent the month of July 2024 setting up her business E. Perry, Naturals. Eliza prepared a new statement of financial position...
-
Financial balances for the car hire business of Terry's Wedding Cars on 31 March 2024 are provided below in a table in accounting equation form similar to the chapter illustrations. During April, the...
-
Trans Clothing Alterations began operations on 1 August 2024 and completed the following transactions during the first month. 1. Tran deposited \($18\) 000 of her personal funds in a current account...
Study smarter with the SolutionInn App