yueyingansha @ 2022-05-06 18:27:56
90分,测试点2RE其余全过,不给下载数据,萌新无力解决问题,又不知道哪里出了问题.求大佬帮忙!
def dfs(nodes, x, y, s):
for i, j in [(x, y + 1), (x, y - 1), (x + 1, y), (x - 1, y)]:
has_yield = False
if 0 <= i < h and 0 <= j < w:
if nodes[i][j] and nums[i][j] > nums[x][y]:
nodes[i][j] = 0
has_yield = True
yield from dfs(nodes, i, j, s + 1)
nodes[i][j] = 1
if not has_yield:
yield s
h, w = [int(i) for i in input().split()]
nums = [[int(i) for i in input().split()] for _ in range(h)]
paths = [[1 for j in range(w)] for i in range(h)]
ans = max([max(dfs(paths, i, j, 1)) for j in range(w) for i in range(h)])
print(ans)
跪求!