Suppose you may have 1 room that you simply need to hire out. (AirBnb model) You need to maximize earnings that you’re going to get by renting it out.
[[1, 10], [2, 5], [7, 20], [23, 30]] – you would hire it out
[2, 5], [7, 20] and [23, 30]
One other instance:
([[1, 2], [1, 11], [5, 8], [4, 33], [18, 72]]) =
Observe: Begin and finish occasions of the interval are inclusive
I carried out a brute pressure resolution to this drawback. First I type by begin time, then I create all doable subsets and take the longest doable worth. This works. However I need to do that utilizing Dynamic programming.
This drawback screams DP, however I’m not in a position to determine if this has an optimum substructure.
My recurrence relation:
f(i, j) = f(i + 1, j) or f(i + nums[i], j) if nums[i].begin > f[i].finish
Can somebody assist me determine the thought behind the dp resolution for the sub-problem?
Observe: this drawback is barely completely different from job scheduling.