The problem is this:
Need to perform n jobs, each characterized by a gain {v1, v2,. . . , vn}, a time required for its implementation {t1, t2,. . . , tn} and a deadline for its implementation {d1, d2,. . . , dn} with d1<=d2<=…..<=d3. Knowing that the gain occurs only if the work is done by that time and that you have a single machine. Must describe an algorithm that computes the maximum gain that is possible to obtain.
I had thought of a recurrence equation with two parameters, one indicating the i-th job and the other shows the moment in which we are implementing : OPT(i,d) , If d+t_i <= d then adds the gain t_i. (then a variant of multiway choice ..that is min for 1<=i<=n).
My main problem is: how can I find jobs that previously were carried out? I use a data structure of support?
As you would have written the equation of recurrence?
thanks you!!!!
My main problem is: how can I find jobs that previously were carried out? I use a data structure of support?
The trick is, you don’t need to know what jobs are completed already. Because you can execute them in the order of increasing deadline.
Let’s say, some optimal solution (yielding maximum profit) requirers you to complete job
A(deadline10) and then jobB(deadline3). But in this case you can safely swapAandB. They both will still be completed in time and new arrangement will yield the same total profit.End of proof.
As you would have written the equation of recurrence?
You already have general idea, but you don’t need a loop (min for 1<=i<=n).
Converting it to DP should be trivial.
If you don’t want
O(n*max_deadline)complexity (e.g., whendandtvalues are big), you can resort to recursion with memoization and store results in a hash-table instead of two-dimensional array.edit
If all jobs must be performed, but not all will be paid for, the problem stays the same. Just push jobs you don’t have time for (jobs you can’t finish before deadline) to the end. That’s all.