DP, O(n^3)/O(n^2), AC