给的是每个事件所在的年代排序位置,求一个最长的增加子序列。

###Code

UVA 111
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//By Brickgao
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

int n, ans;
int rec[30] ,rec1[30], rec2[30], f[30], maxn;

int main() {
int tmp;
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%d", &tmp);
rec1[tmp] = i;
}
while(scanf("%d", &tmp) != EOF) {
rec2[tmp] = 1;
for(int i = 2; i <= n; i ++) {
scanf("%d", &tmp);
rec2[tmp] = i;
}
ans = 0;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= n; j ++) {
if(rec1[i] == rec2[j]) {
rec[j] = i;
break;
}
}
}
memset(f, 0, sizeof(f));
for(int i = n; i >= 1; i --) {
if(!f[i]) f[i] = 1;
for(int j = 1; j < i; j ++) {
if(rec[i] > rec[j]) {
f[j] = max(f[i] + 1, f[j]);
}
}
}
for(int i = 1; i <= n; i ++) {
ans = max(f[i], ans);
}
printf("%d\n", ans);
}
return 0;
}