알고리즘1 [파이썬]최단경로 알고리즘 import random mat = [[random.choice(range(50)) for _ in range(10)] for _ in range(10)] m = len(mat) len(mat) for i in range(m): print(mat[i]) def matrixPath(i, j): if i == 0 and j == 0: return mat[i][j] if j == 0: return matrixPath(i-1, 0) + mat[i][0] if i == 0: return matrixPath(0, j-1) + mat[0][j] return min(matrixPath(i-1, j) + mat[i][j], matrixPath(i, j-1) + mat[i][j]) %timeit matrixPath(m-1.. 2020. 6. 18. 이전 1 다음