You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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()