Advertisement
Pandaaaa906

Untitled

Dec 1st, 2021
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from functools import lru_cache
  2. from itertools import product, chain
  3.  
  4. import numpy as np
  5.  
  6. arr = np.array([[8,4,1],[6,5,2]])
  7.  
  8. def solve(arr_input):
  9.     w, h = arr_input.shape
  10.     @lru_cache
  11.     def gen_dept(x, y):
  12.         return max(chain((
  13.             gen_dept(new_x, new_y)
  14.             for value, (new_x, new_y) in filter(
  15.             lambda c: c[0]<arr_input[x, y],
  16.             ((arr_input[coords], coords)
  17.              for coords in filter(
  18.                 lambda c: w>c[0]>=0 and h>c[1]>=0,
  19.                 ((x-1, y), (x+1, y), (x, y+1), (x, y-1))
  20.             )))), (0, ))) + 1
  21.     print(max(gen_dept(i,j) for i, j in product(range(w), range(h))))
  22.  
  23.  
  24. if __name__ == '__main__':
  25.     solve(arr)
  26.     pass
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement