-
Notifications
You must be signed in to change notification settings - Fork 1
/
solution.cpp
69 lines (61 loc) · 1.14 KB
/
solution.cpp
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
#include <iostream>
#include <algorithm>
using namespace std;
struct box
{
int w, h, index;
} boxes[5005];
bool cmp(const box &fir, const box &sec)
{
if (fir.w ^ sec.w)
return fir.w < sec.w;
return fir.h < sec.h;
}
int chainSizes[5005];
int parents[5005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w, h;
cin >> n >> w >> h;
int validBoxes = 0;
for (int i = 1; i <= n; ++i)
{
int x, y;
cin >> x >> y;
parents[i] = -1;
if (x <= w || y <= h)
continue;
boxes[++validBoxes] = {x, y, i};
}
if (validBoxes == 0)
{
cout << 0 << endl;
return 0;
}
sort(boxes + 1, boxes + validBoxes + 1, cmp);
for (int i = 1; i <= validBoxes; ++i)
{
chainSizes[i] = 1;
for (int j = 1; j < i; ++j)
{
if (boxes[j].w < boxes[i].w && boxes[j].h < boxes[i].h && chainSizes[j] + 1 > chainSizes[i])
{
chainSizes[i] = chainSizes[j] + 1;
parents[i] = j;
}
}
}
int ans = 0, parent = 0;
for (int i = 1; i <= validBoxes; ++i)
{
if (chainSizes[i] > ans)
{
ans = chainSizes[i];
parent = i;
}
}
cout << ans << endl;
return 0;
}