题解 | 滑雪
滑雪
https://www.nowcoder.com/practice/36d613e0d7c84a9ba3af3ab0047a35e0
n, m = map(int, input().split()) arr = [] mat = [] dp = [[1 for _ in range(m)] for x in range(n)] for _ in range(n): arr = list(map(int, input().split())) mat.append(arr) moves = [[0, 1], [0, -1], [1, 0], [-1, 0]] def dfs(x, y, dp): for move in moves: ix, iy = x + move[0], y + move[1] if ix < 0 or ix >= n or iy < 0 or iy >= m: continue if mat[ix][iy] >= mat[x][y]: continue dp[x][y] = max(dp[x][y], dfs(ix, iy, dp) + 1) return dp[x][y] res = 0 for i in range(n): for j in range(m): res = max(res, dfs(i, j, dp)) print(res)