'''迷宫最短路径(二维数组左上角到右下角最小距离,最短路径长度17,路线1->8->2->1->5)
1 4 3
8 7 5
2 1 5'''
def getMinPath(array):
if array==None or len(array)<1:
return 0
row=len(array)
col=len(array[0])
data=[([None]*col) for i in range(row)]
data[0][0]=array[0][0]
for i in range(1,row):
data[i][0]=data[i-1][0]+array[i][0]
for j in range(1,col):
data[0][j]=data[0][j-1]+array[0][j]
for i in range(1,row):
for j in range(1,col):
if data[i][j-1]>data[i-1][j]:
data[i][j]=data[i-1][j]+array[i][j]
else:
data[i][j]=data[i][j-1]+array[i][j]
print(data[row-1][col-1])
if __name__ == '__main__':
array=[[1,4,3],[8,7,5],[2,1,5]]
getMinPath(array)