求最大的包含关系,简单的DP。

###Code

POJ 103
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//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;}

typedef struct record {
int r[11];
int num;
} record;

int n, k, maxn, recmax;
int f[31], t[31];
record rec[31];

bool cmp(record a, record b) {
return a.r[0] < b.r[0];
}

int main() {
while(scanf("%d%d", &k, &n) != EOF) {
maxn = 0;
for(int i = 1; i <= k; i ++) {
for(int j = 0; j < n; j ++) {
scanf("%d", &rec[i].r[j]);
}
rec[i].num = i;
sort(rec[i].r, rec[i].r + n);
}
sort(rec + 1, rec + k + 1, cmp);
memset(t, -1, sizeof(t));
memset(f, 0, sizeof(f));
for(int i = k; i >= 1; i --) {
if(!f[i]) f[i] = 1;
for(int j = 1; j <= k; j ++) {
if(i == j) continue;
bool flag = true;
for(int ii = 0; ii < n; ii ++) {
if(rec[i].r[ii] <= rec[j].r[ii]) {
flag = false;
break;
}
}
if(flag) {
if(f[i] + 1 > f[j]) {
f[j] = f[i] + 1;
t[j] = i;
}
}
}
}
for(int i = 1; i <= k; i ++) {
if(f[i] > maxn) {
maxn = f[i];
recmax = i;
}
}
printf("%d\n", maxn);
while(recmax != -1) {
printf("%d", rec[recmax].num);
if(t[recmax] == -1) {
printf("\n");
}
else {
printf(" ");
}
recmax = t[recmax];
}
}
return 0;
}