Determine the final answer You process all values from up to using the formula The final answer to the problem is simply This dynamic programming solution runs in time and uses space, and it uses memory.
The structure is exactly the same: define the state (what each dp[i] represents), find the transition, set the base cases, and read the final answer from the appropriate state.