dynamic programming to find a target function to get min Edit Distance