You need to define dp[0] and dp[1]. dp[0] tells you the answer for to , which means no number is present to choose, so dp[0] = 0.
When you consider dp[1], you have to consider from to , the only possible value is a[1]. You can either take it or not take it. The best is to take it, so dp[1] = a[1].
With these two base cases in place, you can fill the rest of the table using the recurrence from the previous unit. The final answer sits at dp[n], covering the full range from index to .