classic edit distance dp algorithm from long ago cs course.