Pagini recente » Cod sursa (job #1710776) | Cod sursa (job #2938706) | Cod sursa (job #105698) | Cod sursa (job #1409174) | Cod sursa (job #1223513)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int NMAX = 3505;
struct CUTIE {
int x, y, z;
void read() {
scanf("%d%d%d", &x, &y, &z);
}
};
int n, aib[NMAX][NMAX];
CUTIE c[NMAX];
class cmp {
public:
inline bool operator () (CUTIE a, CUTIE b) {
if(a.x == b.x) {
if(a.y == b.y)
return a.z < b.z;
return a.y < b.y;
}
return a.x < b.x;
}
};
inline int lsb (int x) {
return x & -x;
}
int update (int x, int y, int val) {
int i, j;
for(i = x; i <= n; ++ i)
for(j = y; j <= n; ++ j)
aib[i][j] = max(aib[i][j], val);
}
int query (int x, int y) {
int i, j, ans;
ans = 0;
for(i = x; i > 0; -- i)
for(j = y; j > 0; -- j)
ans = max(aib[i][j], ans);
return ans;
}
int solve() {
int k;
memset(aib, 0, sizeof(aib));
for(k = 1; k <= n; ++ k)
update(c[k].x, c[k].y, query(c[k].x - 1, c[k].y - 1) + 1);
return query(n, n);
}
int main() {
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
int t, i;
scanf("%d%d", &n, &t);
while(t) {
-- t;
for(i = 1; i <= n; ++ i)
c[i].read();
printf("%d\n", solve());
}
return 0;
}