Dynamic Programming: Mission Per Day, Scheduling for Maximum Profit
Dynamically build a table of dimensions 6 x n. The entry table[w_i][d_j] will denote the maximal reachable value when Bob has worked for the last i days consecutively (including today) and it is day j.
The first column is easy to fill in:
table[1][0] = x_0 if Bob decides to work on the first day, all other values are 0 (table[0][0] => Bob doesn't work on the first day, table[2..5][0] => Bob can't work for multiple consecutive days on day 1.)
Go on to complete the table column-by-column according to the following rules:
The maximum value on day j with 0 consecutive days of work is the maximum of any value of the previous day and not working today:
table[0][d_j] = max{ table[0..5][d_j-1] }
The maximum value on day j with 1 consecutive day of work is the maximum of the previous 2 days with no consecutive days of work plus x_j. (It never makes sense to rest more than 2 days, as we could have just worked the day(s) in between.):
table[1][d_j] = max{ table[0][d_j-2], table[0][d_j-1] } + x[d_j]
Otherwise, table[w_i][d_j] = table[w_i-1][d_j-1] + x[d_j].
The solution will be the maximum value in the last column.
The problem:
There is a set of n days that Bob is planning to work, and on each day i there is a mission; each mission lasts exactly one day, must be done on day i in which it is given, and pays bob x_i dollars. Bob cannot work more than 5 consecutive missions at a time. That is, he must take at least 1 rest day every 5 days.
Given numbers x_1...x_n, on which days should Bob perform missions, and on which days should he rest, in order to make as much money as possible and not work more than 5 days? Your solution should be O(n)
My issue:
I am having trouble coming up with the recurrence for this problem. I have been thinking about this problem for a long time. My original thought was to let p[i] = max{x_i + x_i-1 + .... + x_i-4}, where p[i] is the max profit earnable from days i-4 to i. However, I realize, one, that this does take in to account that the optimal solution might have two consecutive work days, and two, I am not building off previous solutions. 
My Question: Can anyone give me insight on understanding the structure of this problem? I feel like I am just not understanding the key properties that would make the solution easy to see.
Thanks in advance!