This is the regular editing dynamic programming, except that the diagonal as an extra possibility with cost = -1 when a swap is possible.
M[I, j] = M[I-1, j-1] - 1 ; if A[I] == B[j-1] and A[I-1] == B[j]