Algorithm to determine coin combinations

后端 未结 13 2540
臣服心动
臣服心动 2020-12-25 08:33

I was recently faced with a prompt for a programming algorithm that I had no idea what to do for. I\'ve never really written an algorithm before, so I\'m kind of a newb at t

13条回答
  •  时光说笑
    2020-12-25 09:00

    Sort the List backwards: [15 10 6 4 2]

    Now a solution for 50 ct can contain 15 ct or not. So the number of solutions is the number of solutions for 50 ct using [10 6 4 2] (no longer considering 15 ct coins) plus the number of solutions for 35 ct (=50ct - 15ct) using [15 10 6 4 2]. Repeat the process for both sub-problems.

提交回复
热议问题