题解 | 滑雪

滑雪

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)

全部评论

相关推荐

05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务