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
| #include <bits/stdc++.h>
using namespace std;
#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define INF 0x3f3f3f3f
#define NINF 0xc0c0c0c0
struct Box {
int id;
vector<int> len;
};
bool boxcmp(const Box &a, const Box &b) {
int sz = a.len.size();
for(int i = 0; i < sz; ++i) {
if(a.len[i] < b.len[i]) return true;
if(a.len[i] > b.len[i]) return false;
}
return true;
}
bool isContain(const Box &a, const Box &b) {
int sz = a.len.size();
for(int i = 0; i < sz; ++i) {
if(a.len[i] <= b.len[i]) return false;
}
return true;
}
void printBox(const vector<int> &prevNesting, const vector<Box> &box, int lastbox, bool printSpace) {
if(lastbox == -1) return;
printBox(prevNesting, box, prevNesting[lastbox], true);
cout << box[lastbox].id;
if(printSpace) cout << " ";
}
int main() {
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
USE_CPPIO();
int k, n;
while(cin >> k >> n) {
vector<Box> box;
for(int i = 0; i < k; ++i) {
int t;
vector<int> tmp;
for(int j = 0; j < n; ++j) {
cin >> t;
tmp.push_back(t);
}
sort(tmp.begin(), tmp.end());
box.push_back({i + 1, tmp});
}
sort(box.begin(), box.end(), boxcmp);
vector<int> maxNesting(k, 1), prevNesting(k, -1);
int maxLen = 1, lastbox = 0;
for(int i = 0; i < k; ++i) {
for(int j = 0; j < i; ++j) {
if(isContain(box[i], box[j])) {
if(maxNesting[j] + 1 > maxNesting[i]) {
maxNesting[i] = maxNesting[j] + 1;
prevNesting[i] = j;
if(maxNesting[i] > maxLen) {
maxLen = maxNesting[i];
lastbox = i;
}
}
}
}
}
cout << maxLen << endl;
printBox(prevNesting, box, lastbox, false);
cout << endl;
}
return 0;
}
|