(S, m, n)
| 9 | |
| 10 | |
| 11 | def dp_count(S, m, n): |
| 12 | |
| 13 | # table[i] represents the number of ways to get to amount i |
| 14 | table = [0] * (n + 1) |
| 15 | |
| 16 | # There is exactly 1 way to get to zero(You pick no coins). |
| 17 | table[0] = 1 |
| 18 | |
| 19 | # Pick all coins one by one and update table[] values |
| 20 | # after the index greater than or equal to the value of the |
| 21 | # picked coin |
| 22 | for coin_val in S: |
| 23 | for j in range(coin_val, n + 1): |
| 24 | table[j] += table[j - coin_val] |
| 25 | |
| 26 | return table[n] |
| 27 | |
| 28 | |
| 29 | if __name__ == '__main__': |