Coin change problem with infinite number of coins of each denomination

后端 未结 5 712
感动是毒
感动是毒 2020-12-09 07:19

I want to know the idea of algorithm for the coin change problem where each denomination has infinte number of coins. Means how to apply DP (like the standard coin change pr

5条回答
  •  天命终不由人
    2020-12-09 07:48

    This is how to translate a number from one numbering system to another. For example:

    35 = 1*2^5 + 0*2^4 + 0*2^3 + 0*2^2 + 0*2^1 + 1*2^0
    

    That is:

    var cash = 35;
    var coins = [15, 10, 5, 1];
    var change = {};
    for(var i=0; i

提交回复
热议问题