Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 455A Boredom - Defining the DP

First 1D DP problem

1.1. Define the states

Let dp[i]dp[i] = maximum points out of values from 11 to ii. You want to compute dp[M]dp[M], where M=max(a1,a2,,an).M = \max(a_1, a_2, \dots, a_n). If you define your dp like this, the base case is simple. **

Now think of the transition (how to compute dp[i] from earlier values). Work through examples by hand before coding. Understanding the pattern makes implementation simple. Practice with similar problems to reinforce your understanding.