Fidn the lowest path

Hi all, this is the 1st time I post here. I don't know whether this has been posted before. If such just give me a URL to see.

Well let me start right now.

I encounter a problem which is a conversion of a similiar problem in the national programming competition of Singapore in 1995.

The problem is as follows:

Given a table m x n size filled with value from 0 to 1.

m: no. of row

n: no. of column

Both m and n do not exceed 20.

Find a sequence of cells going from the first cell (top-leftmost) to the last cell (bottom-rightmost) such that the sum of those cells is the smallest one we can find. We can just move through one cell horizontally or vertically at a time.

For example: we have the following table

0.5 0.8

0.2 0.5

0.1 0.7

The sequence of the smallest sum is (1,1)(2,1)(3,1)(3,2), and hence the smallest sum is 1.5 = 0.5+0.2+0.1+0.7 .

(1,1) means the cell located by 1st row and 1st column.

I'm thinking of the way that we'll go through the ways, and find the smallest. But it seems to become complicated when the table size goes bigger but not exceed 20 x 20.

I'm also thinking of using a Graph with Dijkstra method to find but still get stuck.

[1263 byte] By [janov84a] at [2007-9-28 18:44:41]
# 1
Hi,This looks to be a 'shortest path' problem with n * m nodes. Dijkstra will work nicely on this.Roger
sabre150a at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...
# 2
Check whether there is a constraint that each time you go either right or down. If so, dynamic programming is the way forward.
YATArchivista at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...
# 3

To sabre150: Could you clarify for me how Dijkstra would work well because I'm not familiar with this. If I use Dijkstra, must the graph be directed or not (must it have arrow at the end of each edge) ?

Assume we have a following graph:

http://friends13.host.sk/graph.html

where number on each edge is its weight, x is unknown value.

I dont know whether I use Dijkstra properly but let me try.

In A graph, the sequence of cell would be (1,1)(1,2)(2,2)(3,2)(3,1). Is it right ? Then, it turns to the cell (3,1) which is right below the 1st cell (1,1). The sum of this way is 9.

In other word, we could move directly like the B graph (1,1)(2,1)(3,1) with the sum is 5.

In the problem of Finding lowest path, how can I overcome this ?

janov84a at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...
# 4
Hi,I can't reach your URL so I can't comment on your graph. Can you send it to me?Roger
sabre150a at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...
# 5
http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/dijkstra.htmlyour weight for going from(i1,j1) to (i2,j2)will be the value of your matrix at (i2,j2) therefore, yes the graph is directed.HTHSpieler
spielera at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...
# 6
> Hi,> > I can't reach your URL so I can't comment on your> graph. Can you send it to me?> > RogerIt seems to be dead link. Now I change it to here : http://www.comp.nus.edu.sg/~nguyen10/graph.html
janov84a at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...
# 7
Hi,As 'spieler' says, you have a directed graph.Dijkstra work for both directed and undirected graphs so will be no problem.Roger
sabre150a at 2007-7-12 16:58:47 > top of Java-index,Other Topics,Algorithms...