function MinCoinChange(coins){ var coins = coins.sort(function(a,b){ return b - a; }); this.makeChange = function(amount){ var change = [], total = 0; for (var i = 0; i < coins.length; i++){ var coin = coins[i]; while (total + coin <= amount) { chan…
Description 约翰在镇上买了 T 元钱的东西,正在研究如何付钱.假设有 N 种钞票,第 i 种钞票的面值为 Vi,约翰身上带着这样的钞票 Ci 张.商店老板罗伯是个土豪,所有种类的钞票都有无限张.他们有洁癖,所以希望在交易的时候,交换的钞票张数尽可能地少.请告诉约翰如何恰好付掉 T 元,而且在过程中交换的货币数量最少. Input Format • 第一行:两个整数 N 和 T,1 ≤ N ≤ 100, 1 ≤ T ≤ 10000 • 第二行:n个整数 Vi 第三行:n个整数 Ci,1…
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins,…