Question: We are given an array of distinct positive integers { a 1 = 1 , a 2 , . . . , an } that
We are given an array of distinct positive integers a a an
that denote the denominations of coins in circulation. We are also
given a positive integer x Find the smallest number of coins such
that their sum equals x we let a so that this is always possible
For example, in US the denominations of commonly used coins
are in cents If x then the smallest number of
coins that are needed is two and one
Note that a greedy algorithm, which always selects the largest
denomination possible is not optimal in general. For example, if the
denominations are and x Then the greedy algorithm
will select one coin with denomination then four coins with de
nomination In total, it requires coins. But we know we
can just select two coins of which is optimal.
Write a program to solve this problem. Given a a an
and x the output of the program should include:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
