Pagini recente » Cod sursa (job #1604917) | Cod sursa (job #338261) | Cod sursa (job #1446557) | Cod sursa (job #932237) | Cod sursa (job #2323440)
#define DM 3501
#include <algorithm>
#include <cstring>
#include <fstream>
using namespace std;
ifstream fi ("cutii.in");
ofstream fo ("cutii.out");
int n, t, aux, aib[DM][DM];
struct cutie {
int x, y, z;
bool operator < (const cutie &other) const {
if (x != other.x)
return x > other.x;
if (y != other.y)
return y > other.y;
return z > other.z;
}
} v[DM];
void update(int x, int y, int val) {
int cx, cy, ix;
ix = x;
while (y) {
x = ix;
while (x) {
cx = x - 1;
cx = cx^x;
cx = cx&x;
aib[x][y] = max(val, aib[x][y]);
x-=cx;
}
cy = y - 1;
cy = cy^y;
cy = cy&y;
y-=cy;
}
}
int query(int x, int y) {
int cx, cy, ix, sol;
ix = x;
while (y <= n) {
x = ix;
while (x <= n) {
cx = x - 1;
cx = cx^x;
cx = cx&x;
sol = max(sol, aib[x][y]);
x+=cx;
}
cy = y - 1;
cy = cy^y;
cy = cy&y;
y+=cy;
}
return sol;
}
int main() {
fi >> n >> t;
while (t--) {
for (int i = 1; i <= n; ++i)
fi >> v[i].x >> v[i].y >> v[i].z;
sort(v + 1, v + 1 + n);
for (int i = 1; i <= n; ++i) {
aux = query(v[i].y, v[i].z);
update(v[i].y, v[i].z, aux + 1);
}
fo << query(1, 1) << '\n';
memset(aib, 0, sizeof aib);
}
return 0;
}