MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / dp_count

Function dp_count

dynamic_programming/coin_change.py:11–26  ·  view source on GitHub ↗
(S, m, n)

Source from the content-addressed store, hash-verified

9
10
11def 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
29if __name__ == '__main__':

Callers 1

coin_change.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected