1-D Dynamic Programming Take it or skip it
524. Training Schedule with No Repeated Activity
A training plan runs for n days. On each day you do exactly one of three activities, numbered 0, 1 and 2.
Doing activity j on day i earns points[i][j] points.
You may not do the same activity on two days in a row. An activity may come back after a day of something else.
Return the most points a plan can earn over all n days.
Example 1
Input: points = [[4, 7, 2],
[3, 9, 5],
[8, 1, 6],
[2, 5, 3]]
26Explanation: Do activities 0, 1, 0, 1 for 4 + 9 + 8 + 5 = 26. Taking the best activity of each day in turn gives only 7 + 5 + 8 + 5 = 25, because the 7 on day 0 blocks the 9 on day 1.
Example 2
Input: points = [[0, 6, 0], [0, 6, 0], [0, 6, 0]]
12Explanation: Activity 1 is the only one worth anything, but it cannot fill two days in a row. Doing it on days 0 and 2 gives 12.
Example 3
Input: points = [[1000000000, 0, 1000000000],
[1000000000, 1000000000, 0],
[0, 1000000000, 1000000000]]
3000000000Explanation: Doing activities 0, 1 and 2 earns 109 on every day.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ points.length ≤ 105points[i].length == 30 ≤ points[i][j] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.