AcWing 901. 滑雪 - python 13 行 记忆化搜索
原题链接
简单
作者:
roon2300
,
2020-07-19 14:28:36
,
所有人可见
,
阅读 948
n, m = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
dist = [[-1] * m for _ in range(n)]
def dfs(i,j):
if dist[i][j] > -1: return dist[i][j]
dist[i][j] = 1
cv = mat[i][j]
for dx, dy in zip((-1, 0, 1, 0), (0, -1, 0, 1)):
nx, ny = i + dx, j + dy
if 0 <= nx < n and 0 <= ny < m and mat[nx][ny] < cv:
dist[i][j] = max(dist[i][j], dfs(nx, ny) + 1)
return dist[i][j]
print(max(dfs(i, j) for i in range(n) for j in range(m)))