You can solve this problem like this:
Let M be the largest number in the NxN integer matrix A. Define a new N*N matrix B where b[i,j] = M - a[i,j] + 1
. B contains only positive integers. The traversal method corresponds to a certain well-defined directional graph on the cells of the matrix. Now use the dijkstra algorithm on this graph, where the distances of each node to the three (or two in the cases on the edges) nodes above is simply equal to the number b[i,j]
. The dijkstra algorithm will give you the 'shortest' path in this graph, which corresponds to the path with the largest sum in the matrix A.
To see why the problem can be solved in this way, suppose there are x sequences s1, s2, s3, ..., sx of equal length N. Some sequence si will have the largest sum. If we take sequences t1, t2, ..., tx so that t1k = -s1k, then the largest sum s is the smallest sum t. If we then add a constant to each of the values in each sequence then the t sequence with the largest sum does not change, for each of these sequences is equally long.