coin-change

how do you calculate the minimum-coin change for transaction?

人盡茶涼 提交于 2019-12-31 06:52:33
问题 Hey everyone. I have a question. I am working on Visual Basic Express and I am supposed to calculate the change from a transaction. Now what code would I use? I have it partly working but its starting to get a little confusing. Thank you. For you guys who wanted more information: Say I have one dollar and I go to the store to purchase something. I have to ask the user to put in the amount they spent and then calculate the change and print to the screen. Then I am supposed to use the least

Coin change with limited number of coins

老子叫甜甜 提交于 2019-12-29 01:37:31
问题 I have written a program for generating subset sum which might be used in this problem which states: Suppose, you have 3 $1-coins, 2 $2-coins, 3 $5-coins, 1 $10-coin, there are 4 ways to obtain $10 from those coins. If there are n1 $X1 coins, n2 $X2 coins.... nm $Xm coins, how many ways can we obtain $X from these limited number of coins? If we create a set of { X1, X1..... X1, X2, X2.......... X2, ..., ..., ............, Xm, Xm... Xm}, and then run Subset summing on it, surely we can get a

Dynamic Programming Coin Change Problems

陌路散爱 提交于 2019-12-28 16:07:13
问题 I am having issues with understanding dynamic programming solutions to various problems, specifically the coin change problem: "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. For example, for N = 4 and S = {1,2,3}, there are four solutions: {1,1,1,1},{1,1,2},{2,2},{1,3}. So output should be 4. For N = 10 and S = {2, 5, 3, 6}, there are

Coin change in C# with limited coins

一个人想着一个人 提交于 2019-12-25 02:03:19
问题 I built the following coin change (C#) that works perfectly: class Program { static int amount = 0; static void Main(string[] args) { EnterAmount(); int[] coins = new int[] { 500, 100, 50, 20, 10, 5, 2, 1 }; int Results = 0; for (int i = 0; i < coins.Length; i++) { Results = amount / coins[i]; Console.WriteLine(Results + " x " + coins[i]); amount -= Results * coins[i]; } } static void EnterAmount() { Console.Out.WriteLine("Enter an amount : "); amount = int.Parse(Console.ReadLine()); } } My

Calculating the dollars right in the Money change program - C++ [closed]

纵饮孤独 提交于 2019-12-24 07:59:38
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Please take a look at the below code #include <QtCore/QCoreApplication> #include <iostream> int main(int argc, char *argv[]) { using namespace std;

Dynamic Programming Coin Change Limited Coins

随声附和 提交于 2019-12-23 12:39:21
问题 Dynamic Programming Change Problem (Limited Coins) . I'm trying to create a program that takes as INPUT: int coinValues[]; //e.g [coin1,coin2,coin3] int coinLimit[]; //e.g [2 coin1 available,1 coin2 available,...] int amount; //the amount we want change for. OUTPUT: int DynProg[]; //of size amount+1. And output should be an Array of size amount+1 of which each cell represents the optimal number of coins we need to give change for the amount of the cell's index. EXAMPLE: Let's say that we have

Finding shortest combinations in array/sequence that equals sum

拜拜、爱过 提交于 2019-12-23 09:30:50
问题 I'm totally stuck and have no idea how to go about solving this. Let's say I've an array arr = [1, 4, 5, 10] and a number n = 8 I need shortest sequence from within arr which equals n. So for example following sequences within arr equals n c1 = 5,1,1,1 c2 = 4,4 c3= 1,1,1,1,1,1,1,1 So in above case, our answer is c2 because it's shortest sequences in arr that equals sum. I'm not sure what's the simplest way of finding a solution to above? Any ideas, or help will be really appreciated. Thanks!

Coin change DP solution to keep track of coins

眉间皱痕 提交于 2019-12-23 09:27:19
问题 Trying to program a DP solution for the general coin-change problem that also keeps track of which coins are used. So far I have it working to give me the minimum amount of coins needed but can't figure out how to get which coins were used and how many times. I tried setting up another table (boolean) with values if the coin is used but that doesn't seem to work correctly. Any ideas? public static int minChange(int[] denom, int changeAmount) { int m = denom.length; int n = changeAmount + 1;

Recursive coin change c++

ⅰ亾dé卋堺 提交于 2019-12-13 01:44:57
问题 My program seems to be crashing every time it recursive calling in the minimum function. Can anyone tell me why it is crashing. It would instantly freeze after i call the minimum function. Is it because im using a vector? #include <iostream> #include <vector> #include <math.h> #include <algorithm> using namespace std; int minimum(vector<int> denom, int s, int N) //take in denomination , sizeofcoin, and value of N { if(N == 0) { return 1; } else if(N < 0 || (N > 0 && s <=0)) { return 0; } else

Prolog : coin change

烈酒焚心 提交于 2019-12-12 16:26:37
问题 I am new to prolog, trying to solve this classic coin change problem. change(M,P,N,D) with formula that M>=0 and M = P+5*N+10*D here is my approach change(M,P,N,D) :- M is P+5*N+10*D, P is M - (5*N+10*10). couple of test-cases change(100,10,8,5). True change(X,10,8,5). X = 100. However, if I try change(100,P,8,5). it gives me "Arguments are not sufficiently instantiated" instead of P = 10. what is casuing this ? edit : fix my code by using between predicate between(0,M,P),between(0,M,N)