Olympiad in Informatics

Dilworth's Theorem and the Missile Interception Problem

This is a problem I thought about for a long time, probably because I'm too weak. Let's first analyze the problem.

Question 1

This question asks for the maximum number of missiles one system can intercept. Abstracting it, we can conclude that this question is really asking us to find the longest non-increasing sequence in this sequence. Let's first analyze the sample input.

389 207 155 300 299 170 158 65

Clearly, for this sequence, its longest non-increasing sequence is \(389,300,299,170,158,65\). So how do we find this subsequence with the best algorithm?

Greedy Strategy

First we set a pointer variable cursor = 0, which records the algorithm's current position in sequence S. We then set a variable pos = 0, which records the tail position of our subsequence H.

If S[cursor]>H[pos], we can put S[cursor] directly at the tail of H, i.e. H[++pos] = S[cursor]. Otherwise, within H[0:pos], i.e. the range from 0 to pos, we can always find the first value smaller than S[cursor] (in fact, we can use binary search to find this value, because the sequence H is already sorted), and we set H[bias] = S[cursor]. Repeat this over and over.

Why assign S[cursor] to the first element in the sequence H that is smaller than S[cursor]? Because once we assign this value, when we need to insert data later, it becomes easier to add numbers (because at the same position, the larger the value, the smaller the restriction on numbers added later), and that makes this subsequence the longest.

And if we're after a \(\Theta(n \log n)\) approach, we need binary search. Next I'll introduce two functions.

lower_bound(start, end, key, [cmp])

When called, this function returns the address of the first element in a sorted sequence that is greater than or equal to (if a cmp function is passed in, that's another story) key.

upper_bound(start, end, key, [cmp])

When called, this function returns the address of the first element in a sorted sequence that is greater than (if a cmp function is passed in, that's another story) key.

Strangely, these two functions are completely different from what their names literally say: with no cmp argument passed in, upper_bound and lower_bound assume the same default ordering of the sequence. Used together, they give you the magical speed of \(\Theta(n \log n)\).

Question 2

Dilworth's Theorem

In a sequence of numbers, the number of maximum non-increasing subsequences is the length of the maximum increasing subsequence. And vice versa.

For a weakling like me, all Dilworth's theorem can help me with is this one sentence. I have looked through many blogs, and through Combinatorics too, and I never found a statement that was easy to understand. After I came across a peerless masterpiece, I boiled my understanding down to this one sentence. For OIers, this sentence is the most powerful part of Dilworth.

Approach

The question in Question 2 is to find the number of missile defense systems. By Dilworth's theorem, the number of systems should equal the length of the maximum non-decreasing subsequence. So, following the greedy idea from Question 1, we can easily work out by analogy the greedy strategy for finding the maximum non-increasing subsequence in this problem. So I won't go over it again here.