|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
Finding
the best alignment
|
|
|
|
has
become finding the best
|
|
|
path
through a table
|
|
|
| • |
Position
(i,j) in the table can
|
|
|
be
reached from
|
|
|
|
– |
Position
(i,j-1)
|
|
|
|
• |
At
cost -1
|
|
|
|
– |
Position
(i-1,j)
|
|
|
|
• |
At
cost -1
|
|
|
|
– |
Position
(i-1,j-1)
|
|
|
|
• |
At
cost <table entry>
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
BestPathCost
(table T[1..n,1..n]):
|
|
|
// C[i,j] represents best cost
|
|
|
// to reach position (i,j) in T
|
|
|
C[0,0] = 0
|
|
|
for i =
1 to n do C[i,0] = -i;
|
|
|
for j =
1 to n do C[0,j] = -j;
|
|
|
for i =
1 to n do
|
|
|
for j = 1 to n do
|
|
|
C[i,j] = max{ C[i,j-1] - 1,
|
|
|
C[i-1,j] - 1,
|
|
|
C[i-1,j-1] + T[i,j] };
|
|
return
C[n,n];
|
|
|
|