---
id: 42
lang: en
translation_of: index.md
source_sha256: 8c01283dc78c8e77610fb8a589602254f86be6254ff15a68f9e891d5c5313e4a
title: "Dilworth's Theorem and the Missile Interception Problem"
description: "Finding the longest non-increasing subsequence with a greedy plus binary search, then using Dilworth's theorem to count the systems needed."
tags: ["Missile Interception Problem","Dynamic Programming","Greedy","Dilworth","Binary Search"]
translated: 2026-11-27
translator: Claude Opus 5.5
translator_model: claude-opus-5-5
translation_notes:
  - "拍好了顺序 is read as a typo for 排好了顺序 (already sorted); the doubled 的的 typo is not reproduced."
  - "最大 in the quoted statement of Dilworth's theorem and in the last section is rendered literally as “maximum”, not corrected to “minimum number of” or “longest”."
  - "The last paragraph's switch between 不下降 (non-decreasing) and 不上升 (non-increasing) is kept as written."
---

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 <span class="slang" data-zh="蒟蒻" data-gloss="jǔruò, “konjac”, a pun on 巨弱 (jù ruò), “very weak”. Self-deprecating word for oneself.">a weakling</span> 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.
