def f(v, i, S, memo):
    if i >= len(v):
        return 1 if S == 0 else 0
if (i, S) not in memo:
    count = f(v, i + 1, S, memo)
count += f(v, i + 1, S - v[i], memo)
memo[i, S] = count
return memo[i, S]
v = [1, 2, 3, 10]
sum = 12
memo = dict()
print(f(v, 0, sum, memo))
Algorithm to find which number in a list sum up to a certain number