Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def __init__(self):
- self.path = []
- def compress(self, a, b, s):
- def helper(a, b, n, index, sum, path, s):
- if sum > s:
- return
- if index == n:
- if sum == s:
- self.path = path
- return
- helper(a, b, n, index + 1, sum + a[index], path + [a[index]], s)
- helper(a, b, n, index + 1, sum + b[index], path + [b[index]], s)
- n = len(a)
- helper(a, b, n, 0, 0, [], s)
- return self.path
- s = Solution()
- a = [12, 16, 30]
- b = [4, 15, 3]
- s.compress(a, b, 30)
- print(s.path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement