Pagini recente » Cod sursa (job #1320932) | Cod sursa (job #1527663)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream in("cutii.in");
ofstream out("cutii.out");
const int MAX_N = 3500;
struct Box {
int x;
int y;
int z;
};
int n;
int AIB[1 + MAX_N][1 + MAX_N];
Box B[1 + MAX_N];
int lsb(int x) {
return x & (-x);
}
void reset() {
int i, j;
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
AIB[i][j] = 0;
}
}
}
void update(int x, int y, int val) {
int i, j;
for(i = x; i; i -= lsb(i)) {
for(j = y; j; j -= lsb(j)) {
AIB[i][j] = max(AIB[i][j], val);
}
}
}
void reset(int x, int y) {
int i, j;
for(i = x; i; i -= lsb(i)) {
for(j = y; j; j -= lsb(j)) {
AIB[i][j] = 0;
}
}
}
int query(int x, int y) {
int i, j, ans = 0;
for(i = x; i <= n; i += lsb(i)) {
for(j = y; j <= n; j += lsb(j)) {
ans = max(ans, AIB[i][j]);
}
}
return ans;
}
bool boxSort(Box A, Box B) {
return A.z > B.z;
}
int main() {
int t, i, ans, val;
in >> n >> t;
while(t--) {
for(i = 1; i <= n; i++) {
in >> B[i].x >> B[i].y >> B[i].z;
}
sort(B+1, B+n+1, boxSort);
ans = 1;
update(B[1].x, B[1].y, 1);
for(i = 2; i <= n; i++) {
val = query(B[i].x, B[i].y) + 1;
ans = max(ans, val);
update(B[i].x, B[i].y, val);
}
for(i = 1; i <= n; i++) {
reset(B[i].x, B[i].y);
}
out << ans << '\n';
}
return 0;
}