Given Length of Rod and P (Price ) for the first 3 rods. We are to fill in the possible price we can get for the rest of rods. Assuming we can cut the longer pieces as needed.
L = 1 2 3 4 5 6 7 8
p = 3 8 12
We basically want to get the maximum price we can get for each missing length price.
My approach I believe that since we are given the best possible price for a rod of length 1,2, and 3 we can generate all possible combinations for the next rods.
For example to get price of rod where L = 4
price of rod where L = 1 + rod where L = 3 = 15
price of rod where L = 2 + rode where L = 2 = 16
Therefore price of rod wehre L = 4 = 16 since 16 > 15.
For example to get price of rod where L = 5
price of rod where L = 1 + rod where L = 2 and rod where L = 2 = 19
price of rod where L = 3 + rod where L = 2 = 20
price of rod where L = 4 + rod where L = 1 = 19
So this is kind of the approach i am following. However I am not sure if i am correct. I would also like it if someone can verify this approach and also maybe help me derive a formula from this. I am not looking for code as understanding the problem is enough to write the code.