/
BOJ2643.cpp
74 lines (55 loc) · 1.06 KB
/
BOJ2643.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
70
71
72
73
74
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <functional>
using namespace std;
#define MAX_N 100
#define INF 2000000000
#define MOD
int N;
int cache[MAX_N + 1];
void swap(int& a, int& b)
{
int t = a;
a = b;
b = t;
}
int main(int argc, char** argv)
{
int tc, T;
std::ios::sync_with_stdio(false);
#ifdef _WIN32
freopen("Text.txt", "r", stdin);
#endif
//cin >> T;
T = 1;
for (tc = 0; tc < T; tc++)
{
cin >> N;
vector<pair<int, int> > v(N);
for (int i = 0; i<N; i++)
{
cin >> v[i].first >> v[i].second;
if (v[i].first < v[i].second)
swap(v[i].first, v[i].second);
cache[i] = 1;
}
sort(v.begin(), v.end(), greater<pair<int, int> >());
for (int i = 0; i < N - 1; i++)
{
for (int j = i + 1; j < N; j++)
{
if (v[i].first >= v[j].first && v[i].second >= v[j].second
&& cache[i] + 1 > cache[j])
cache[j] = cache[i] + 1;
}
}
int ans = cache[0];
for (int i = 1; i < N; i++)
ans = max(ans, cache[i]);
cout << ans;
}
return 0;
}