def dfs(matrix,path,i,j,cache): if(cache[i][j] != 0): return cache[i][j] for k in range(len(path)): x,y = i+path[k][0],j+path[k][1] if(x >= 0 and x < len(matrix) and y >= 0 and y < len(matrix[0]) and matrix[i][j] > matrix[x][y]): cache[i][j] = max(cache[i][j],dfs(matrix,path,x,y,cache)) cache[i][j] = cache[i][j] + 1 return cache[i][j] line = input().split() m = int(line[0]) n = int(line[1]) matrix = list() cache = list() for i in range(m): line = input().split() matrix.append(list()) cache.append(list()) for j in range(n): matrix[i].append(line[j]) cache[i].append(0) if(m == 0): print(0) else: path = [[-1,0],[0,-1],[1,0],[0,1]] mmax = 0 for i in range(m): for j in range(n): mmax = max(mmax,dfs(matrix,path,i,j,cache)) print(mmax)
点赞 评论

相关推荐

Hello_WordN:咱就是说,除了生命其他都是小事,希望面试官平安,希望各位平时也多注意安全
点赞 评论 收藏
分享
Java抽象带篮子:难蚌,点进图片上面就是我的大头😆
点赞 评论 收藏
分享
牛客网
牛客企业服务