Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #рекурсия для задачи с камнями
- from icecream import ic
- from functools import lru_cache
- @lru_cache(None)
- def f(x, y):
- # ic(x, y)
- if x + y <= 20:
- # ic('<= 20')
- return 0
- # ic('вернули 0')
- if x == 0:
- # ic()
- # ic('x == 0')
- moves = [f(x, y - 1), f(x, int(y / 2) + y % 2)]
- return 0
- if x == 1:
- # ic()
- # ic('x == 1')
- moves = [f(x - 1, y), f(x, y - 1), f(x, int(y / 2) + y % 2)]
- return 0
- if y == 0:
- # ic()
- # ic('y == 0')
- moves = [f(x - 1, y), f(int(x / 2) + x % 2, y)]
- return 0
- if y == 1:
- # ic()
- # ic('x == 1')
- moves = [f(x - 1, y), f(x, y - 1), f(int(x / 2) + x % 2, y)]
- return 0
- else:
- moves = [f(x - 1, y), f(x, y - 1), f(int(x / 2) + x % 2, y), f(x, int(y / 2) + y % 2)]
- lose = [i for i in moves if i <= 0]
- # ic(moves)
- # ic(lose)
- if lose:
- result = -max(lose) + 1
- else:
- result = -max(moves)
- return result
- ic.configureOutput(prefix='')
- for s in range(11, 50):
- if f(10, s) == 2:
- ic(s, f(10, s))
- ic('=====================')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement