KiK0S

Untitled

Feb 21st, 2021
483
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. used = {}
  3. def solve(a, b):
  4.     global used
  5.     if (a, b) in used:
  6.         return used[(a, b)]
  7.     if a + b >= 41:
  8.         used[(a, b)] = 0
  9.         return 0
  10.     res = solve(a + 1, b)
  11.     if res == 0:
  12.         used[(a, b)] = 1
  13.         return 1
  14.     res = solve(a * 2, b)
  15.     if res == 0:
  16.         used[(a, b)] = 1
  17.         return 1
  18.     res = solve(a, b + 1)
  19.     if res == 0:
  20.         used[(a, b)] = 1
  21.         return 1
  22.     res = solve(a, b * 2)
  23.     if res == 0:
  24.         used[(a, b)] = 1
  25.         return 1
  26.     used[(a, b)] = 0
  27.     return 1
RAW Paste Data