I'm trying to create a game but I am having some difficulties in coming up with a suitable algorithm for my problem. I have elements from 1 to n and I am trying to cover all of the elements using the minimum amount of elements as possible. Each element can cover an amount of elements to the left (x direction) and an amount of elements to the right direction (y direction) I'm trying to get all of them connected, meaning that if i pick one element z, each pair of adjacent elements i and i+1 should be covered from z. The goal is to find the minimum amount of elements in order to cover the entire 1 to n elements.
This is an example:
If n= 7 [so i have a list with n elements, it can be mountaints, towers, etc.]
x= 0 1 1 2 1 1 1 [how many elements you can cover to the left]
y= 1 2 1 2 1 1 0 [how many elements you can cover to the right]
#as you can see, in element 2, you can cover 1 element to the left, and 2 elements to the right(look at index 1 if counting from 0 in the x list and y list)
To clarify, the reason it is 0 in the first x element, is because you can cover 0 elements to the left, and 0 in the last y element because you can cover 0 elements to the right. So from each element i, you can cover everything from i-xi and i+yi.
Answer: we could pick elements 2, 4 and 7 to cover all of the 7 elements (there are many other combinations). So the minimum would be 3 which is the right answer for this input
The reason why I dont pick element 2 and 6,(one might think they cover all of them) is because that would leave a gap between element 4 and 5 where they are not connected. So the minimum is not 2, but 3
How can I go about to solve this?
I have looked at interval scheduling, as well as vertex cover, but vertex cover would not solve the issue that you cant cover the same amount of elements both ways, for example, element 4 can cover ut to element 6 in my example, but not vice versa. I have looked at dynamic programming and greedy algorithms, but they do not seem to solve the connecting issue, and would give the output of 2 and not 3, so Im a bit lost in how to tackle this. I am hoping that there is someone out there that can help me on the way, any advice, recommendations, youtube clips, pages and such are highly appreciated. Thank you in advance. If there are any clarifications needed let me know.