Pagini recente » Cod sursa (job #2455285) | Cod sursa (job #2875046) | Cod sursa (job #2057283) | Cod sursa (job #1715767) | Cod sursa (job #2263161)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;
int n;
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[3501];
int aib[3501][3501];
int lsb(int x) {
return x & -x;
}
int query(int x, int y) {
int result = 0;
while (x > 0) {
int ty = y;
while (ty > 0) {
result = max(result, aib[x][ty]);
ty -= lsb(ty);
}
x -= lsb(x);
}
return result;
}
void update(int x, int y, int value) {
while (x <= n) {
int ty = y;
while (ty <= n) {
aib[x][ty] = max(aib[x][ty], value);
ty += lsb(ty);
}
x += lsb(x);
}
}
void reset(int x, int y) {
while (x <= n) {
int ty = y;
while (ty <= n) {
aib[x][ty] = 0;
ty += lsb(ty);
}
x += lsb(x);
}
}
void solve() {
int x, y, z;
for (int i = 1; i <= n; ++i) {
scanf("%d %d %d", &x, &y, &z);
boxes[i] = { x,y,z };
reset(x, y);
}
sort(boxes + 1 , boxes + n + 1);
int gbest = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i - 1; j > 0; --j) {
if (boxes[j].contains(boxes[i])) {
update(boxes[i].x, boxes[i].y, max(query(boxes[i].x, boxes[i].y), query(boxes[j].x, boxes[j].y) + 1));
}
}
gbest = max(query(boxes[i].x, boxes[i].y), gbest);
}
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;
}