UVa 526 - String Distance and Transform Process

Summary
Given three operations (insert, delete, replace) and two strings, calculate the lowest cost of transforming the first string into the second one. Generate the list of operations for such a transformation as well.

Explanation
A typical edit distance problem, with all three of the possible operations having the same cost.

Gotchas

 * Be careful with empty lines.
 * Be careful with the position of operations (i.e. the i-th character). It might have changed due to deletion and insertion.

Implementations
You can put the list of operation into the DP as well. This is easier to program, since no trace-back is not needed. However, it would be slow.

Optimizations
Do not put the list of operation into DP. Do a separate trace-back to get the sequence of operations. (See the solution below)

Input
abcac bcd aaa aabaaaa

boy apple

yoyo oyoy hello_world hello_old

Output
3 1 Delete 1 2 Delete 3 3 Replace 3,d

4 1 Insert 1,a 2 Insert 2,a 3 Insert 3,b 4 Insert 4,a

3 1 Insert 1,b 2 Insert 2,o 3 Insert 3,y

5 1 Delete 1 2 Delete 1 3 Delete 1 4 Delete 1 5 Delete 1

2 1 Delete 1 2 Insert 4,y

2 1 Delete 7 2 Delete 8