-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp081.java
More file actions
32 lines (26 loc) · 921 Bytes
/
p081.java
File metadata and controls
32 lines (26 loc) · 921 Bytes
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
package level04;
import org.junit.Test;
import data.IPoint;
import lib.EulerTest;
import lib.Graph;
public class p081 extends EulerTest {
final int N = 80;
final Object START = "start";
/**
* Find the minimum sum of numbers on a path from the top left to the bottom right going only
* right or down through the specified NxN grid.
*/
@Test
public void test() {
long[][] grid = readAsGrid(",");
Graph<Object> graph = Graph.create();
graph.addDirectedEdge(START, new IPoint(0, 0), grid[0][0]);
for (int i : range(N))
for (int j : range(1, N)) {
graph.addDirectedEdge(new IPoint(i, j - 1), new IPoint(i, j), grid[i][j]);
graph.addDirectedEdge(new IPoint(j - 1, i), new IPoint(j, i), grid[j][i]);
}
ans = graph.bellmanFord(START, new IPoint(N - 1, N - 1));
check(427337);
}
}