Dynamic programming · 12 / 15 Exercise Hard

Ways to make change

Objective

In how many different ways can an amount be formed with coins of certain values, with as many coins of each as you want? Here combinations are counted (1+2 is the same as 2+1). The order of the loops decides whether combinations or sequences are counted.

Instructions

  • The first line has the amount (integer ≥ 0) and the second the coin values.
  • Show Ways: n with the number of combinations.
Input
5
1 2 5
Output
Ways: 4

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise