Question
Problem 4. We want to purchase an item of price n and for that we have an unlimited (!) supply of three types of coins
Problem 4. We want to purchase an item of price n and for that we have an unlimited (!) supply of three types of coins with values 5, 9, and 13, respectively. Our goal is to purchase this item using the smallest possible number of coins or outputting that this is simply not possible. Design a dynamic programming algorithm for this problem with worst-case runtime of O(n). (25 points) Example. A couple of examples for this problem: Given n = 17, the answer is not possible (try it!). Given n = 18, the answer is 2 coins: we pick 2 coins of value 9 (or 1 coin of value 5 and 1 of value 13). Given n = 19, the answer is 3 coins: we pick 1 coin of value 9 and 2 coins of value 5. Given n = 20, the answer is 4 coins: we pick 4 coins of value 5. Given n = 21, the answer is not possible (try it!). Given n = 22, the answer is 2 coins: we pick 1 coin of value 13 and 1 coin of value 9. Given n = 23, the answer is 3 coins: we pick 1 coin of value 13 and 2 coins of value 5.
Problem 4. We want to purchase an item of price n and for that we have an unlimited (!) supply of three types of coins with values 5, 9, and 13, respectively. Our goal is to purchase this item using the smallest possible number of coins or outputting that this is simply not possible. Design a dynamic programming algorithm for this problem with worst-case runtime of O(n). (25 points) Example. A couple of examples for this problem: Given n = 17, the answer is not possible (try it!). Given n= 18, the answer is 2 coins: we pick 2 coins of value 9 (or 1 coin of value 5 and 1 of value 13). Given n= 19, the answer is 3 coins: we pick 1 coin of value 9 and 2 coins of value 5. Given n = 20, the answer is 4 coins: we pick 4 coins of value 5. Given n = 21, the answer is "not possible" (try it!). Given n = 22, the answer is 2 coins: we pick 1 coin of value 13 and 1 coin of value 9. Given n = 23, the answer is 3 coins: we pick 1 coin of value 13 and 2 coins of value 5. Challenge Yourself. Suppose we have two arrays A[1 : n] and B[1 : m] which are both in the sorted order and are consisting of distinct numbers. Design an algorithm that given an integer 1Step 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