Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- used = {}
- def solve(a, b):
- global used
- if (a, b) in used:
- return used[(a, b)]
- if a + b >= 41:
- used[(a, b)] = 0
- return 0
- res = solve(a + 1, b)
- if res == 0:
- used[(a, b)] = 1
- return 1
- res = solve(a * 2, b)
- if res == 0:
- used[(a, b)] = 1
- return 1
- res = solve(a, b + 1)
- if res == 0:
- used[(a, b)] = 1
- return 1
- res = solve(a, b * 2)
- if res == 0:
- used[(a, b)] = 1
- return 1
- used[(a, b)] = 0
- return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement