Pagini recente » Cod sursa (job #1271342) | Cod sursa (job #2243888) | Cod sursa (job #2570213) | Cod sursa (job #631011) | Cod sursa (job #613692)
Cod sursa(job #613692)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct struct_cutie {
int a, b, c;
};
vector <int> vect_max;
vector <struct_cutie> vect_cutii;
int getMax(void);
inline bool compare(struct_cutie, struct_cutie);
inline bool fits(struct_cutie, struct_cutie);
int main(void) {
int n, m;
ifstream fin("cutii.in");
fin >> n >> m;
vect_cutii.resize(n);
vect_max.resize(n);
ofstream fout("cutii.out");
for(int i = 0; i < m; ++i) {
for(int j = 0; j < n; ++j)
fin >> vect_cutii[j].a >> vect_cutii[j].b >> vect_cutii[j].c;
fout << getMax() << '\n';
}
fin.close();
fout.close();
}
inline bool compare(struct_cutie a, struct_cutie b) {
if(a.a < b.a) return true;
if(a.a == b.a && a.b < b.b) return true;
if(a.a == b.a && a.b == b.b && a.c < b.c) return true;
return false;
}
inline bool fits(struct_cutie a, struct_cutie b) {
return a.a < b.a && a.b < b.b && a.c < b.c;
}
int getMax(void) {
int m = 1;
sort(vect_cutii.begin(), vect_cutii.end(), compare);
vect_max.assign(vect_max.size(), 1);
for(int i = 1; i < vect_max.size(); ++i)
for(int j = i - 1; j >= 0; --j)
if(fits(vect_cutii[j], vect_cutii[i]) && vect_max[i] < vect_max[j] + 1) {
vect_max[i] = vect_max[j] + 1;
m = max(m, vect_max[i]);
}
return m;
}