classSolution:defminPathSum(self,matrix: List[List[int]]) ->int:import sys sys.setrecursionlimit(100000)from functools import lru_cache@lru_cache(maxsize=None)defdfs(i,j):if i ==0and j ==0:return matrix[i][j]if i ==0:returnsum(matrix[i][j] for j inrange(j +1))if j ==0:returnsum(matrix[i][j] for i inrange(i +1))return matrix[i][j] +min(dfs(i -1, j), dfs(i, j -1)) m, n =len(matrix),len(matrix[0])returndfs(m -1, n -1)