#P13296. [GCJ 2013 #2] Erdős–Szekeres
[GCJ 2013 #2] Erdős–Szekeres
题目描述
Given a list , consisting of the numbers , an increasing subsequence is a subset of these numbers which appears in increasing order, and a decreasing subsequence is a subset of those numbers which appears in decreasing order. For example, is an increasing subsequence of .
Nearly 80 years ago, two mathematicians, Paul Erdős and George Szekeres proved a famous result: is guaranteed to have either an increasing subsequence of length at least or a decreasing subsequence of length of at least . For example, has a decreasing subsequence of length 4: .
I am teaching a combinatorics class, and I want to "prove" this theorem to my class by example. For every number in the sequence, I will calculate two values:
- : The length of the longest increasing subsequence of that includes as its largest number.
- : The length of the longest decreasing subsequence of that includes as its largest number.
The key part of my proof will be that the pair is different for every i, and this implies that either or must be at least for some i. For the sequence listed above, here are all the values of and :
0 | 4 | 1 | 4 |
1 | 5 | 2 | |
2 | 3 | 1 | 3 |
3 | 7 | 3 | 4 |
4 | 6 | 3 | |
5 | 2 | 1 | 2 |
6 | 8 | 4 | |
7 | 1 |
I came up with a really interesting sequence to demonstrate this fact with, and I calculated and for every , but then I forgot what my original sequence was. Given and , can you help me reconstruct ?
should consist of the numbers in some order, and if there are multiple sequences possible, you should choose the one that is lexicographically smallest. This means that should be as small as possible, and if there are still multiple solutions, then should be as small as possible, and so on.
输入格式
The first line of the input gives the number of test cases, . test cases follow, each consisting of three lines.
The first line of each test case contains a single integer . The second line contains positive integers separated by spaces, representing . The third line also contains positive integers separated by spaces, representing .
输出格式
For each test case, output one line containing "Case #x: ", followed by in order, and separated by spaces.
2
1
1
1
8
1 2 1 3 3 1 4 1
4 4 3 4 3 2 2 1
Case #1: 1
Case #2: 4 5 3 7 6 2 8 1
提示
Limits
- .
- It is guaranteed that there is at least one possible solution for .
Small dataset (9 Pts, Test set 1 - Visible)
- .
Large dataset (15 Pts, Test set 2 - Hidden)
- .