instead of DP, using an array to record result.
Nice algorithm to be memorized.