In this homework problem, you will implement the dynamic programming solution to the weighted interval scheduling problem described in Chapter 6 of Jon Kleinberg's and Éva Tardos' Algorithm Design textbook. Available at Prof. Kevin Wayne's Algorithms Course Webpage at Princeton University.
After studying the above materials, you need to implement the algorithms in slides 6-15 inside the Python skeleton provided. You can make small modifications to the skeleton if needed to correct errors or make improvements.
n = 20 JobsList = \ [0, job('job1', 24, 28, 100 ), \ job('job2', 16, 17, 98 ), \ job('job3', 2, 10, 16 ), \ job('job4', 20, 23, 16 ), \ job('job5', 4, 19, 86 ), \ job('job6', 28, 30, 36 ), \ job('job7', 22, 31, 18 ), \ job('job8', 18, 31, 13 ), \ job('job9', 3, 17, 5 ), \ job('job10', 17, 21, 6 ), \ job('job11', 14, 28, 14 ), \ job('job12', 7, 21, 68 ), \ job('job13', 2, 10, 2 ), \ job('job14', 21, 29, 67 ), \ job('job15', 17, 32, 40 ), \ job('job16', 20, 34, 3 ), \ job('job17', 20, 29, 89 ), \ job('job18', 25, 34, 80 ), \ job('job19', 0, 8, 2 ), \ job('job20', 12, 20, 72 ) \ ]
Consider the coin changing problem: Given coin denominations and an amount to be paid, devise a method to pay that amount using the fewest possible number of coins.
When we study greedy algorithms, we'll see that the greedy cashier's strategy (i.e., at each iteration we add a coin of the largest denomination that does not take us past the amount to be paid) produces an optimal solution IF the coin denominations are those of the US coins (i.e., 1, 5, 10, 25, and 100 cents). However, for other denominations, this greedy cashier's strategy might not be optimal. For example, if the coin denominations are {1, 10, 21, 34, 70, 100}, and the amount to be paid is 140 cents then the greedy cashier strategy will produce {100, 34, 1, 1, 1, 1, 1, 1} for a total of 8 coins, when the optimal answer is {70, 70} with a total of 2 coins.
In this problem you are asked to provide a dynamic programming solution to the coin changing problem that always produces an optimal solution (i.e., minimum number of coins) regardless of the coin denominations.
Input:
Output:
Solve this problem following the steps below.
Hint: Consider using a 2-dimensional array OPT[1..n][0..M], where OPT[i,j] = the minimum number of coins that are needed to make change for j cents using only the first i coin denominations d1,...,di, where 1 ≤ i ≤ n, and 0 ≤ j ≤ M (both i and j are integer numbers).Find a recurrence relation that expresses the solution of OPT[i,j] in terms of the solutions of slightly "smaller" problems (i.e., other cells in the matrix OPT whose values can be calculated before). Include suitable boundary conditions for the recurrence relation. Based on this, determine in what order you'll calculate the values of the cells in OPT. Explain.