I don't know where you got the fibonacci numbers from (the original recursive relation had (j - i)^2)
Regardless, the easiest way would be to keep track of a parent array while doing the dp. For example:
def getTimes(aliens):
n = len(aliens)
dp = [0] * n #your s array. I'm just used to using dp for dp tables
parent = [-1] * n
dp[1] = 1
for i in range(2, n):
max = 0; #assuming there can't be a negative number of aliens.
for j in range(0, i):
x = dp[j] + min(int(aliens[i]), (i - j) * (i - j))
if(x >= max):
max = x
parent[i] = j
dp[i] = max;
times = getTimesRec(n - 1, [], parent)
return times
def getTimesRec(i, times, parent):
if(i == -1):
return times
getTimesRec(parent[i], times, parent)
times.append(i)
return times
I haven't tested this, but the idea behind it should be fine. Essentially whenever you figure out when the last alien was shot you keep track of it in the parent array. You can then go from the end and store the times into a list in reverse order recursively (as shown) or using a stack.
You could also probably make this run in O(nlogn) by using a binary search similar to longest increasing subsequence. I'm too lazy to think about how to do it.
Edit: Hopefully I can clear up some of the confusion. All the parent array does is store when the previous shot occurred given a time frame.
So for example let's say that you shoot at time 4, 19, and 23. This means that the parent array looks like this:
parent[23] = 19
parent[19] = 4
parent[4] = -1
So given this array we can figure out the reverse order of times by just adding 23 to a list then parent[23] then parent[parent[23]] and so on until we reach -1. The recursion is just there to reverse this chain all in one step.