[algogeeks] Re: Solving coin change problem with limited coins.

2014-05-20 Thread s khadar
The main difference between the standard CC algo, and the one with limited coin supply is the maximum value that we can form with the given coins. For example : In stranded CC coins[] = {1,2,3} then we can can form denominations to any value(assuming that coin with 1 value will always be the

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-20 Thread Don
Shashwat, very nice. Don -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-19 Thread Don
In my solution, the line which reads: if (sum < result) sum = result; Should read if (sum < result) result = sum; Don On Friday, May 16, 2014 11:51:52 PM UTC-4, Shashwat Anand wrote: > > @Don > int coins [] = {1, 3, 5}; > int cnt [] = {7, 3, 1}; > int S = 9; > Your code returns 9, for the

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-16 Thread Shashwat Anand
@Don int coins [] = {1, 3, 5}; int cnt [] = {7, 3, 1}; int S = 9; Your code returns 9, for the aforementioned test case. Should not it return 3 ? Here is my take which takes O (|number of denominators| x |S| x |maximum count for any coin|) time and O (|number of denominators| x |S|) time. It is

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-16 Thread Don
If you find a way to do that for more than a few coins I'd be interested in seeing it too. Don On Thursday, May 15, 2014 3:00:04 PM UTC-4, atul007 wrote: > > @Don : i am intersted in DP bottom up approach with less time complexity. > solving it recursively is a simpler approach... > On 15 May 201

Re: [algogeeks] Re: Solving coin change problem with limited coins.

2014-05-15 Thread atul anand
@Don : i am intersted in DP bottom up approach with less time complexity. solving it recursively is a simpler approach... On 15 May 2014 22:25, "Don" wrote: > How about this: > > const int N = 6; > unsigned int coins[N] = {100,50,25,10,5,1}; > unsigned int count[N] = {2, 1, 1, 5, 4, 10}; > int be

[algogeeks] Re: Solving coin change problem with limited coins.

2014-05-15 Thread Don
How about this: const int N = 6; unsigned int coins[N] = {100,50,25,10,5,1}; unsigned int count[N] = {2, 1, 1, 5, 4, 10}; int best = 10; int minCoins(int s, int f=0, int d=0) { if (d == 0) best = s; // It can never take more than s coins if (s < 1) return 0; // No coins required