a O(m*n) DP, accepted