You are on page 1of 1

III.

Dynamic Programming: Trick or Treat, Again (33 points total)


In this problem we consider a dierent Trick-or-Treat scenario. You still live on a street with n houses. For each house i in this problem, you are given the number ni of pieces of candy that the people in house i will hand out. You are also given an integer waiting time ti (measured in seconds) for each house. (Some people answer the door more slowly than others.) As before, you may visit each house at most once. Your objective is to collect at least m pieces of candy from the n houses with the minimum total waiting time. (Collecting more than m pieces is OK.) That is, nd a subset S of the n houses such that

iS

ni m

and

iS

ti is minimized.

For the questions below, your analysis should be given in terms of the number of houses n and the sum of the waiting times: T =
n i=1

ti .

1. (8 points) Show that the greedy strategy that collects candy based on the ratio ni /ti (largest to smallest) does not result in the optimum solution. (Give a counterexample.) 2. (15 points) Describe a dynamic programming algorithm for this problem. Be sure to describe the choices and subproblems involved in English. Do not use pseudo-code. 3. (5 points) Describe how the minimum total waiting time for a problem relates to the minimum total waiting time for its subproblems. 4. (5 points) Analyze and justify the running time of your dynamic programming algorithm.

You might also like