DP solution to partition