Pagini recente » Statistici Suma dorin (Simadorin) | Cod sursa (job #215280) | Cod sursa (job #2635566) | Monitorul de evaluare | Cod sursa (job #2263114)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int n;
int dp[3500];
int longest[3500];
struct Box {
int x, y, z;
bool operator<(Box &rhs) {
return z > rhs.z;
}
bool contains(Box &other) {
return x >= other.x && y >= other.y;
}
};
Box boxes[3500];
void solve() {
int x, y, z;
for (int i = 0; i < n; ++i) {
scanf("%d %d %d", &x, &y, &z);
boxes[i] = { x,y,z };
dp[i] = 1;
longest[i] = 1;
}
sort(boxes , boxes + n);
int gbest = 0;
for (int i = 0; i < n; ++i) {
for (int j = i - 1; j >= 0; --j) {
if (boxes[j].contains(boxes[i])) {
dp[i] = max(dp[i], dp[j] + 1);
}
if (dp[i] >= longest[j]) {
break;
}
}
gbest = max(dp[i], gbest);
if (i > 0) {
longest[i] = max(dp[i], longest[i - 1]);
}
}
printf("%d\n", gbest);
}
int main() {
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
int t;
scanf("%d %d", &n, &t);
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}