-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathBoxStackingProblem.cpp
More file actions
40 lines (28 loc) · 897 Bytes
/
BoxStackingProblem.cpp
File metadata and controls
40 lines (28 loc) · 897 Bytes
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
#include<bits/stdc++.h>
using namespace std;
class SortCriterion{
public:
bool operator()(vector<int>& a, vector<int>& b){
return a[0] < b[0];
}
bool compare(vector<int>& a, vector<int>& b){
for(int i = 0; i < a.size(); i++)
if(a[i] >= b[i]) return false;
return true;
}
};
int solution(vector<vector<int>>& boxes){
int n = boxes.size();
vector<int> lis(n, 1);
SortCriterion check;
sort(boxes.begin(), boxes.end(), check);
for(int i = 1; i < n; i++)
for(int j = 0; j < i; j++)
if(check.compare(boxes[j], boxes[i]))
lis[i] = max(lis[i], lis[j] + 1);
return *max_element(lis.begin(), lis.end());
}
int32_t main(){
vector<vector<int>> a = {{3,9,9}, {1,4,10}, {5,10,11}, {3,9,3}, {1,5,3}, {7, 12, 1}};
cout << solution(a);
}