Pagini recente » Cod sursa (job #1916940) | Monitorul de evaluare | Cod sursa (job #1240468) | Cod sursa (job #846979) | Cod sursa (job #953846)
Cod sursa(job #953846)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in ("cutii.in");
ofstream out ("cutii.out");
const int MAXN = 3510;
struct cutie
{
int x, y, z;
} V[MAXN];
int AIB[MAXN][MAXN];
int N;
inline int lsb (int x)
{
return x & (-x);
}
void set (int x, int y)
{
int i, j;
for (i = x; i <= N; i += lsb (i))
for (j = y; j <= N; j += lsb (j))
AIB[i][j] = 0;
}
void update (int x, int y, int val)
{
int i, j;
for (i = x; i <= N; i += lsb (i))
for (j = y; j <= N; j += lsb (j))
if (AIB[i][j] < val)
AIB[i][j] = val;
}
int query (int x, int y)
{
int i, j, ret = 0;
for (i = x; i; i -= lsb (i))
for (j = y; j; j -= lsb (j))
if (AIB[i][j] > ret)
ret = AIB[i][j];
return ret;
}
inline bool comp (const cutie &A, const cutie &B)
{
return A.z < B.z;
}
int main()
{
int T, i, j, now, Ans;
in >> N >> T;
while (T --){
for (i = 1; i <= N; i ++)
in >> V[i].x >> V[i].y >> V[i].z;
sort (V + 1, V + N + 1, comp);
Ans = 0;
for (i = 1; i <= N; i ++){
now = query (V[i].x, V[i].y) + 1;
if (now > Ans)
Ans = now;
update (V[i].x, V[i].y, now);
}
out << Ans << "\n";
for (i = 1; i <= N; i ++)
set (V[i].x, V[i].y);
}
return 0;
}