dynamic programming - recursion

103 Views Asked by At

We have $n$ requests to plant trees. Each request comes with a position $p_i$ which means we have to plant the tree $p_i$ meters away from a specific constant point. Also, there should not be another tree for $k_i$ meters from another tree. What is the max number of trees we can plant given that $p_i < p_{i+1}$?

I came up with the following for the recursion to solve subproblems $R(i)$ but I'm not sure if it is correct:

$$ R(1) = 1 $$

$R(i) = \max(R(j) + 1) $ if $ j < i $ and $ p_i - k_i > p_j$ and $p_j + k_j < p_i$.

Thanks!