To solve this problem, we can use a method called dynamic programming. We'll create a table where the rows represent the different types of bills, and the columns represent the target sums of money we want to form.
Let's go step by step:
1. Start by creating a table with rows representing the different types of bills and columns representing the target sums.
- In this case, we have four types of bills: $2, $5, $10, and $20.
- For the target sums, we can start from $0 and go up to the maximum possible sum, which is $2 + 3*$5 + 2*$10 + $20 = $72.
2. Initialize the first row and first column of the table with zeros.
- This is because we can always form a sum of $0 by not using any bills.
3. Fill in the table using the following rules:
- For each cell (i, j), where i represents the type of bill and j represents the target sum:
- If the bill amount (i) is greater than the target sum (j), simply copy the value from the cell above, i.e., the value for the same bill type but the previous target sum.
- Otherwise, calculate the value for this cell by subtracting the bill amount from the target sum and adding the value from the cell above.
- For example, if the current cell represents $10 bill and the target sum is $20, we can use the $10 bill and check the remaining sum of $10.
- To find the remaining sum, we need to look at the previous row (i.e., same target sum but different type of bill), which represents the case where we haven't used the current bill yet.
4. The value in the bottom-right cell of the table represents the total number of different sums that can be formed using the given bills.
Using this method, we can derive the solution. Let's go through the steps:
Table:
| | $0 | $1 | $2 | ... | $72 |
|---|----|----|----|-----|-----|
| $2 | 1 | 0 | 1 | ... | ... |
| $5 | 1 | | | | |
| $10 | 1 | | | | |
| $20 | 1 | | | | |
Starting with the first row:
- For $2 bill, we can form a sum of $0 and $2, so we mark those cells as 1.
- For any other target sum, since $2 is smaller than the sum, we copy the value from the cell above (in this case, 0).
Next, we move on to the $5 bill:
- For $5 bill, we can form a sum of $0, $5, $7, $10, $12, $15, $17, $20, $22, $25, $27, $30, $32, $35, $37, $40, $42, $45, $47, $50, $52, $55, $57, $60, $62, $65, $67, $70, $72.
- To calculate the value for each target sum, we subtract $5 from the target sum and add the value from the cell in the previous row. For example, to calculate the value for $10, we look at the cell with target sum $5 in the previous row, which has a value of 1.
Continuing this process for the $10 and $20 bill rows, we eventually reach:
Table:
| | $0 | $1 | $2 | ... | $72 |
|---|----|----|----|-----|-----|
| $2 | 1 | 0 | 1 | ... | 23 |
| $5 | 1 | 0 | 1 | ... | |
| $10 | 1 | 0 | 1 | ... | |
| $20 | 1 | 0 | 1 | ... | |
The value in the bottom-right cell is 23, which means there are 23 different sums of money that can be formed using the given bills.