题解 | 滑雪

滑雪

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)

全部评论

相关推荐

雪飒:我也遇见过,我反问他有考虑来华为od吗?
点赞 评论 收藏
分享
04-13 18:10
门头沟学院 Java
想熬夜的小飞象在秋招:被腾讯挂了后爸妈以为我失联了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务