Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import lru_cache
- from itertools import product, chain
- import numpy as np
- arr = np.array([[8,4,1],[6,5,2]])
- def solve(arr_input):
- w, h = arr_input.shape
- @lru_cache
- def gen_dept(x, y):
- return max(chain((
- gen_dept(new_x, new_y)
- for value, (new_x, new_y) in filter(
- lambda c: c[0]<arr_input[x, y],
- ((arr_input[coords], coords)
- for coords in filter(
- lambda c: w>c[0]>=0 and h>c[1]>=0,
- ((x-1, y), (x+1, y), (x, y+1), (x, y-1))
- )))), (0, ))) + 1
- print(max(gen_dept(i,j) for i, j in product(range(w), range(h))))
- if __name__ == '__main__':
- solve(arr)
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement