improved version of dp, O(mn) time and O(n) space, AC