The data above can be represented with the following 1-dimensional graph
In the image above there are three houses at positions 0, 2 and 4. There are also three bases at positions 1, 2 and 3. Each one has a radius of R = 1 to cover other places and an associated cost to build and set up.
Working towards the optimal solution can be done recursively by considering a new house each time. A precondition to the algorithm is that both the houses and the bases should be ordered (and their costs along with them).
Finding the minimum cost for the first house is easy: there is no previous solution with 0 houses so we need to choose the minimum-cost base which also covers the first house.
Adding the second house means either
The previous solution has this new house in range, therefore it’s the best match we could find
The previous solution cannot be used (insufficient range) - find a new minimum-cost base which can cover this house
The previous solution cannot be used and we found no bases with the house in range - problem is unsolvable with the given data
The algorithm follows
The algorithm runs in \( O(NM) \) and has a preprocessing step of respectively \( O(N\log{N}) \) and \( O(M\log{M}) \).