Edit distance of word using dp