Maximize 5-independent gifts on a path
Here is some pseudocode that illustrates the recursive idea.

If you choose to take this element, then you have to skip ahead 6 steps.
Otherwise you skip this element and go to the next.

def solve(array, index):
    if index &gt;= len(array):
        return 0
    this_one       = array[index]             # the value x_i
    opt_five_steps = solve(array, index + 6)  # the opt of array[i+6:]
    opt_successor  = solve(array, index + 1)  # the opt of array[i+1:]
    return max(this_one + opt_five_steps,
               opt_successor)

Clearly, this can be turned into a DP algorithm, or memoized as is.