The minimum number of coins the sum of which is S

后端 未结 12 1353
我寻月下人不归
我寻月下人不归 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:39

    I don't know about dynamic programming but this is how I would do it. Start from zero and work your way to S. Produce a set with one coin, then with that set produce a two-coin set, and so on... Search for S, and ignore all values greater than S. For each value remember the number of coins used.

提交回复
热议问题