[FrontPage] [TitleIndex] [WordIndex

Note: You are looking at a static copy of the former PineWiki site, used for class notes by James Aspnes from 2003 to 2012. Many mathematical formulas are broken, and there are likely to be other bugs as well. These will most likely not be fixed. You may be able to find more up-to-date versions of some of these notes at http://www.cs.yale.edu/homes/aspnes/#classes.

1. Space Station Cleanup

The solution is to use dynamic programming. The tricky part is that on a ring it's not clear where to start. So we consider two cases: in case 1, we clear bay 1; in case 2, we don't (and thus must clear bays n and 2). This reduces the problem to two problems on a line, in which we want to find the minimum number of Leptons to remove. This we can solve easily.



And now we just call Line twice:



2. Rocket to Russia

This, too, is a job for dynamic programming. The first idea is that we can compute the optimal schedule for days 1..i for each set of of packages left over that must be sent on day i+1. Unfortunately this may require considering as many as 2m different sets of leftover packages. But we only really care about the total weight the leftovers add to the day i+1 rocket, and this will be an integer in the range 0..5m, which is nicely linear, allowing us to use the same approach as in knapsack with small item weights. So we can solve the problem as follows:



We've left out the details of how to compute all the subset sums in the middle step in the loop, but using the same technique as used for knapsack we can easily do this in w*mi = O(m2) time, where mi is the number of items shipped on day i. The total cost of the min operation in the innermost loop is O(m); the cost of the inner loop is O(m2); so the cost of the outer loop at the algorithm is O(nm2).

2014-06-17 11:58