Questions tagged [coin-change]

All problems (regardless of currency) with making change from a given amount of currency into a number of coins and bills of varying denominations.

All problems with making change from a given amount of currency into a number of coins and bills of varying denominations.

For example, finding the correct number of $20, $10, $5, $1 bills and $0.25, $0.10, $0.05, and $0.01 coins that add up to a given sum.

Variations of the problem are to find any solution, all the solutions, the one with the least number of coins / bills, or with a specific number of them.

260 questions
0
votes
1 answer

Coin Change Optimization

I'm trying to solve this problem: Suppose I have a set of n coins {a_1, a2, ..., a_n}. A coin with value 1 will always appear. What is the minimum number of coins I need to reach M? The constraints are: 1 ≤ n ≤ 25 1 ≤ m ≤ 10^6 1 ≤ a_i ≤…
0
votes
1 answer

Bottom-up approach to minimum number of coins for change

I am constructing a bottom-up approach to the coin change problem. I have to give the minimum number of coins needed to give the change requested. It may be possible that the change could not be given because the given denominations cannot form the…
0
votes
1 answer

algorithm-coin changing code mistake

Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn’t matter. I have written below code but it is always…
newbie_old
  • 500
  • 5
  • 19
0
votes
1 answer

Coin exchange method with value of power of 2 PYTHON

Once the machines take over, the denomination of every coin will be a power of two: 1-cent, 2-cent, 4-cent, 8-cent, 16-cent, etc. There will be no limit to how much a coin can be worth. A set of coins makes change for n if the sum of the values of…
0
votes
1 answer

Explain(how do I understand) what the dynamic programming task is asking (uva 166)

uva 166 - dp problem here Thus if we need to pay 55c, and we do not hold a 50c coin, we could pay this as 2*20c + 10c + 5c to make a total of 4 coins. If we tender $1 we will receive 45c in change which also involves 4 coins, but if we tender $1.05…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
0
votes
1 answer

why can not I reuse same coin in coin change dp?

Example: Given 20$, I want to count WAYS to exchange 20$ with coins = { 5$,10$, 15$} The order of coins doesn’t matter. solution here The solution says : total num of ways = using coin + not use the coin : total_ways = count( S,…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
0
votes
2 answers

Coin-counting game for making change

I'm doing a Python programming course and I've been trying to wrap my head around how I can make it happen. I've written some code and I'm trying to fix any errors that pop up but I'm getting confused and not solving anything which is why I turn to…
Omar Khan
  • 15
  • 1
  • 6
0
votes
1 answer

An algorithm for the mellon-selling farmer

Question i saw on the net: A melon-selling farmer has n melons. The weight of each melon, an integer (lbs), is distinct. A customer asks for exactly m pounds of uncut melons. Now, the farmer has the following problem: If it is possible to satisfy…
Raidenlee
  • 56
  • 1
  • 9
0
votes
1 answer

Coin Change C++

I've tried to solve a coin change problem in such a way that it'll compute the minimum numbers of coins that can be used. I've used the algorithm post on http://www.algorithmist.com. Here's the algorithm: C(N,m) = min(C(N,m - 1),C(N - Sm,m) +…
Stefan4024
  • 694
  • 1
  • 10
  • 21
0
votes
2 answers

Variation on coin-change

So the typical coin-change problem asks you to figure out whether or not you can make change for a value v using unlimited coins of denomination x1, x2, ... , xn, but I was wondering how you might go about figuring out the same problem using each…
Evan LaHurd
  • 977
  • 2
  • 14
  • 27
0
votes
2 answers

If I use dynamic programming to solve coin-change, what will the matrix be for memoization?

I'm confused as to what the matrix should look like for the dynamic programming technique of the coin problem. Say I have the denominations of 1c,5c,10c and 25c and i call the make-change(10). i.e. I want to make change for 10 cents, what should my…
Phoenix
  • 8,695
  • 16
  • 55
  • 88
0
votes
3 answers

DP - Counting coin change

The problem requires to count number of coin changes for a particular cost. For example, if I have coin values of 50, 20, 10, 5, 1, I can form costs of: 5 => (5), (11111), which are 2 ways. 10 => (10), (5, 5), (5, 11111), (11111, 11111), which are 4…
user586399
0
votes
2 answers

What are the base cases for Coin Change using Recursion?

I am basically trying to solve the coin change problem through recursion and here is what i have so far -: #include #include using namespace std; int a[]={1,2,5,10,20,50,100,200},count=0; //i is the array index we are working…
Ambar
  • 112
  • 11
-1
votes
1 answer

trying to write a code following a textbook prompt

textbook prompt: BETTERCHANGE is not a correct algorithm. Suppose we were changing 40 cents into coins with denominations of c1 = 25, c2 = 20, c3 = 10, c4 = 5, and c5 = 1. BETTERCHANGE would incorrectly return 1 quarter, 1 dime, and 1 nickel,…
riven
  • 27
  • 4
-1
votes
1 answer

Racket Function for Changing 2 and 1 Euro with 10 Cents and 20 Cents

Can somebody explain me a code in Racket in which I change 2 Euro and a 1 Euro Coin with 10 Cents and 20 Cents? I can only change one time a 2 Euro coin and one time a 1 Euro coin. With 20 Cents and 10 Cents. Here is my code: (define (change sum…