programming-examples/python/Algorithms/count_solutions.py
2019-11-15 12:59:38 +01:00

16 lines
250 B
Python

def count_solutions(a, b):
dp = [0] * (b + 1)
dp[0] = 1
for i in range(len(a)):
for j in range(a[i], b + 1):
dp[j] += dp[j - a[i]]
return dp[b]
def test():
print(5 == count_solutions([1, 2, 3], 5))
test()