Dynamic Programming Solution Template In each problem, we ask you to present dynamic…
- User
Dynamic Programming Solution Template
In each problem, we ask you to present dynamic programming algorithms. Dynamic programming can be very tricky and this template will help guide you through solving new problems. For any problem asking you to give a dynamic programming algorithm, we urge you to get in the habit of going through the list below and filling everything out step by step. The percentage in parenthesis for each item is the weight that we allocate for the item. To receive full credit, all of the items below should be correctly provided.
- (20%) An English description of: (a) the set of subproblems you define, (b) the recurrence you write, and (c) the logic behind your recurrence.
- (30%) The actual recurrence (including base cases).
- (5%) The final value your algorithm needs to return.
- (25%) The algorithm you use to solve the recurrence, written in pseudocode. You may use either a top-down or bottom-up approach.
- (20%) An analysis of your algorithm’s running time.
Problem: You have a budget of B dollars and want to buy as many books as possible from a bookstore. The bookstore offers n different types of books, each priced at p1, p2,..., pn dollars. You may assume all the costs are positive so pi > 0 for every i. (a) Using the template laid out at the beginning of this document, describe a dynamic programming algorithm that determines the maximum number of books you can purchase while spending all of your money. If it is not possible to spend all of the B dollars, the algorithm should return “Impossible”. For example, if there are two types of books priced p1 = 2 and p2 = 5, and you have a budget of B = 9 dollars, you can buy a maximum of three books, one of the second type and two of the first type. If, on the other hand, B = 3, your algorithm should return “Impossible”.
- Assistant