/*Given a monetary amount, write a program which outputs a combination of different denominations of coins which add up to the amount. The algorithm should use the minimum number of coins.*/
var s=[1,2,3,4,5]
m=5
n=5;
function count(s,m,n){
if(n==0)
return 0;
if(n <= 0)
return 0;
if(m <= 0 && n >= 1)
return 0;
return Math.min(count(s,m-1,n),count(s,m,n-s[m-1]))+1
}
//alert(count(s,m,n))
var s=[1,2,3,4,5,6,10]
m=7
n=10;
var dp = new Array();
for(k=0; k <= n+1; k++){
dp[k] = n+1;
}
function count1(s,m,n){
dp[0] = 0;
for(i=1;i <= n+1;i++){
for(j=0;j<m;j++){
if(s[j] <= i)
dp[i] = Math.min(dp[i],dp[i-s[j]]+1)
}
}
alert(dp[n])
}
count1(s,m,n)
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.