Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def subset_sum(L, k, n) :
- if (n == 0):
- return True
- if (k == 0 and n != 0):
- return False
- if (k > len(L)):
- return False
- if (L[k - 1] > n) :
- return subset_sum(L, k - 1, n);
- return subset_sum(L, k-1, n) or subset_sum(L, k-1, n-L[k-1])
- print(subset_sum([2,3,4], 2, 5))
- print(subset_sum([2,3,4], 3, 9))
- print(subset_sum([2,3,4], 2, 8))
- print(subset_sum([2,3,4], 12, 8))
- print(subset_sum([2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18], 5, 100))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement