-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem82.awk
53 lines (46 loc) · 868 Bytes
/
problem82.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
BEGIN {
line = 0;
FS = ",";
width = 80;
height = 80;
}
{
for (x = 0; x < NF; x++) {
arr[x, line] = $(x+1);
}
line++;
}
END {
for (y = 0; y < height; y++) {
acc[0, y] = arr[0, y];
}
for (x = 1; x < width; x++) {
for (y = 0; y < height; y++) {
mincost = acc[x - 1, y] + arr[x, y];
for (y0 = 0; y0 < height; y0++) {
cost = acc[x - 1, y0]
if (y < y0) {
a = y;
b = y0;
} else {
a = y0;
b = y;
}
for (curr = a; curr <= b; curr++) {
cost += arr[x, curr];
}
if (cost < mincost) {
mincost = cost;
}
}
acc[x, y] = mincost;
}
}
final = acc[width - 1, 0]
for (y = 0; y < height; y++) {
if (acc[width - 1, y] < final) {
final = acc[width - 1, y];
}
}
print final;
}