欧拉,projecteuler Problem 83



Problem 83
f = file('83.txt','r')

A = []
for l in f:
  A.append([int(i) for i in l.split(',')])

f.close()

N = 80

B = []
for i in range(N):
  B.append([1000000 for i in range(N)])

B[0][0] = A[0][0]


iter = 5

for _ in range(iter):
  for i in range(0,N):
    for j in range(0,N):
      if 0<i:
        B[i][j] = min(B[i][j],B[i-1][j]+A[i][j])
      if 0<j:
        B[i][j] = min(B[i][j],B[i][j-1]+A[i][j])
      if i<N-1:
        B[i][j] = min(B[i][j],B[i+1][j]+A[i][j])
      if j<N-1:
        B[i][j] = min(B[i][j],B[i][j+1]+A[i][j])

print B[N-1][N-1]


你可能感兴趣的:(projecteuler)