Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 < d2 < ··· < dk, and infinitely many coins of each denomination, find the minimum number of coins needed to make exact change for n zonks.
Here we ask a different problem. Each coin has a weight, the weight of each coin with denomination di being wi > 0. We want to make exact change while minimizing the total weight of the coins used.
(a) Suppose the denominations are 1, 5, 10, 25, 50 with respective weights 1, 2, 2, 6, 12. Give the optimal solution for n = 60.
(b) Describe in detail a dynamic programming algorithm to make change for n zonks such that the total weight of coins used is minimized, and give its asymptotic worst-case running time.
#include<stdio.h>
int count( int S[], int m, int n )
{
int i, j, x, y;
// We need n+1 rows as the table is consturcted in bottom up manner using
// the base case 0 value case (n = 0)
int table[n+1][m];
// Fill the enteries for 0 value case (n = 0)
for (i=0; i<m; i++)
table[0][i] = 1;
// Fill rest of the table enteries in bottom up manner
for (i = 1; i < n+1; i++)
{
for (j = 0; j < m; j++)
{
// Count of solutions including S[j]
x = (i-S[j] >= 0)? table[i - S[j]][j]: 0;
// Count of solutions excluding S[j]
y = (j >= 1)? table[i][j-1]: 0;
// total count
table[i][j] = x + y;
}
}
return table[n][m-1];
}
// Driver program to test above function
int main()
{
int arr[] = {1, 2, 3};
int m = sizeof(arr)/sizeof(arr[0]);
int n = 4;
printf(" %d ", count(arr, m, n));
return 0;
}
Recall the coin changing problem: given coins of denomination di zonks, where 1 = d1 <...
1. [10 pts.] Consider the following coin changing problem. You are given a value N and an infinite supply of coins with values di, d2,.. , dk. Give an O(Nk) algorithm for finding the smallest number of coins that add up to the value N.
Making Change: Given coins of denominations (value) 1 = v1 < v2< … < vn, we wish to make change for an amount A using as few coins as possible. Assume that vi’s and A are integers. Since v1= 1 there will always be a solution. Formally, an algorithm for this problem should take as input: An array V where V[i] is the value of the coin of the ith denomination. A value A which is the amount...
Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...
1.13 (Counterfeit Coin Problem) We are given six coins, one of which is counterfeit and is known to have different weight than the rest. Construct a strategy to find the counterfeit coin using a two-pan scale in a minimum average number of tries. Hint: There are two initial decisions that make sense: (1) test two of the coins against two others, and (2) test one of the coins against one other.
Write a program that tells what coins to give out for as change from 1 cent to 99 cents. Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies) only. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Solution Demo Hello I am the coin machine! I will give you the least number of coins for your change....
We are given n,x1,x2,...,xn,d1,d2,...,dn,D. The graph is not given and it should be constructed. The time it takes to construct a graph is part of the overall time complexity, so it should be included. The solution is your algorithm, which includes the graph construction. It is fine if the algorithm consists of several parts, which perform different tasks. The algorithm should return the actual path.The proof and run-time analysis should be provided for the entire solution/algorithm. Please show your wrok....
Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...
C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...
In Problem Set 7 you designed and implemented a Message class. This time, let's design and implement a Mailbox class in a file named Mailbox java. Do the following with this class • You may use the Message class from PS 7. You will have to add new features to the Message class from PS 7 as you work through this problem. You are welcome to start with my sample solution if you wish • Suppose there are multiple mail...
FART I TRUE FALSE QUESTIONS (10 points). Please write True (1) or False (F) on the blank Scarcity is the intimited nature of society's resources given society's limited wants 2. A reward is a type of positive incentive. 3. To remove difficulty of double coincidence of wants we use money. 4. An exogenous factor is a variable that can be controlled for inside the model. 5. The PPF will not have a constant slope. 6. The law of demand states...