You are on page 1of 2

Cmpt-307

Petra Berenbrink

Project #2
The problem You are part of a mission on the planet Pandora and you are responsible
for defending the base against attacking aliens. The defense of the base requires a lot of
soldiers to be on duty. Therefore, you have become interested in automated methods that
can help fend off attacks by swarms of aliens. The alien attacks have the following pattern.
1. A swarm of aliens arrives over the course of n minutes; in the ith minute, xi aliens
arrive. Based on remote sensing, you know the sequence x1 , . . . , xn in advance.
2. You can schedule an electromagnetic pulse (EMF), which can destroy some of the aliens
as they arrive; the EMFs power depends on how long its been allowed to charge up.
To make this precise, there is a function f () so that if j minutes have passed since the
EMF was last used, then it is capable of destroying up to f (j) aliens.
3. So specifically, if it is used in the kth minute, and it has been j minutes since it was
previously used, then it will destroy min(xk , f (j)) aliens. (After this use, it will be
completely drained.)
4. We will also assume that the EMF starts off completely drained, so if it is used for the
first time in the jth minute, then it is capable of destroying up to f (j) aliens.
Given the data on alien arrivals, x1 , . . . , xn , and given the recharging function f (), choose
the points in time at which youre going to activate the EMF so as to destroy as many aliens
as possible.
Table 1: The best solution would be to activate the EMF in the 3rd and the 4th minute. In
the 3rd minute, the EMF has gotten to charge for 3 minutes, and so it destroys min(10, 4) = 4
aliens; In the 4th minutes, the EMF has only gotten to charge for 1 minute since its last use,
and it destroys min(1, 1) = 1 aliens. This is a total of 5.
1 2 3 4
i
xi
1 10 10 1
f (i) 1 2 4 8

Your task (Dynamic Programming)


1. Find a buddy and work together. If you cannot find a buddy you may work alone.

2. Describe an array and say how to obtain an optimal value from your array. (For example second line of page 6 of http://www.cs.sfu.ca/CourseCentral/307/petra/slides/matrixchain.pdf)
The less dimensions your array has, the better!

3. Give a recurrence for your array. (For example last line of page 6 of http://www.cs.sfu.ca/CourseCentr
Explain your recurrence.
4. Analyze the running time of your algorithm and give the size of your array.
5. Implement an algorithm (in any programming language) for filling the array which
outputs the optimal solution.
6. Write a report including the description of the array, the recurrence, the time analysis,
the size of the array and your output for the files a.txt (see below)
7. Upload the report and the code. (Just one of the 2 person team. Mention both names
in the report)
The data for the upcoming alien attacks. (Use those as the input for the algorithm)
n = 1000
a.txt (can be found on the webpage) which describes xi for 1 i n.
f (i) is the ith Fibonacci number: http : //en.wikipedia.org/wiki/F ibonacci number.
Grading
1. The runtime of the algorithm (in asymptotic notation. For example O(n4 ))
2. The size of the array (in asymptotic notation)
3. Correctness of your output.
4. Quality(6= quantity) of the report. (The report may not exceed 2 pages)
Defend your base!

You might also like