给定下面的数据,找到从左下角到右上角的最高价值路线。
[{ 0, 0, 0, 6 },
{ 2, 0, 0, 2 },
{ 0, 1, 1, 1 },
{ 3, 0, 0, 0 }]
go can only move right (east) or up (north)
Highest value route here is 3 -> 0 -> 1 -> 1 -> 1 -> 2 ->6 = 14
我应该如何处理这个问题。我下面作为伪代码的方法是否正确?
max = 0
array = defined_array
i = len(array)
k = 0
def path(i,j):
total = 0
for j in range(4):
k = j;
total = total + int(array[i][j])
if total > max:
max = total
return path(--i,k)
key= 3
def path(i,j):
for i in range(i):
for j in range(array[i]):
total = total + array[i][j]
守着一只汪
Qyouu
相关分类