The minimum number of coins the sum of which is S

后端 未结 12 1364
我寻月下人不归
我寻月下人不归 2020-11-30 05:06

Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many coins of one type a

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 05:45

    I think the approach you want is like this:

    You know that you want to produce a sum S. The only ways to produce S are to first produce S-V1, and then add a coin of value V1; or to produce S-V2 and then add a coin of value V2; or...

    In turn, T=S-V1 is producible from T-V1, or T-V2, or...

    By stepping back in this way, you can determine the best way, if any, to produce S from your Vs.

提交回复
热议问题