|
@@ -1,23 +1,19 @@
|
|
|
#!/usr/bin/env python
|
|
#!/usr/bin/env python
|
|
|
-from numpy import array
|
|
|
|
|
-
|
|
|
|
|
-m = array([l.split(',') for l in open('matrix.txt', 'r').readlines()],
|
|
|
|
|
- dtype=int)
|
|
|
|
|
-h, w = m.shape
|
|
|
|
|
|
|
+m = [map(int, line.split(',')) for line in open('matrix.txt', 'r').readlines()]
|
|
|
|
|
+h, w = len(m), len(m[0])
|
|
|
|
|
|
|
|
def add(x, y):
|
|
def add(x, y):
|
|
|
global m
|
|
global m
|
|
|
-
|
|
|
|
|
p = []
|
|
p = []
|
|
|
- if x: p.append(m[y, x - 1])
|
|
|
|
|
- if y: p.append(m[y - 1, x])
|
|
|
|
|
- m[y, x] += min(p)
|
|
|
|
|
|
|
+ if x: p.append(m[y][x - 1])
|
|
|
|
|
+ if y: p.append(m[y - 1][x])
|
|
|
|
|
+ m[y][x] += min(p)
|
|
|
|
|
|
|
|
-for i in range(w+h):
|
|
|
|
|
- for x in range(i + 1):
|
|
|
|
|
|
|
+for i in xrange(w + h):
|
|
|
|
|
+ for x in xrange(i + 1):
|
|
|
y = i - x
|
|
y = i - x
|
|
|
|
|
|
|
|
if (x or y) and x < w and y < h:
|
|
if (x or y) and x < w and y < h:
|
|
|
add(x, y)
|
|
add(x, y)
|
|
|
|
|
|
|
|
-print m[h - 1, w - 1]
|
|
|
|
|
|
|
+print m[h - 1][w - 1]
|