Pagini recente » Cod sursa (job #1549425) | Cod sursa (job #2203602) | Cod sursa (job #1767708) | Cod sursa (job #308215) | Cod sursa (job #997838)
Cod sursa(job #997838)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int NMAX = 3505;
int T, N, FT[NMAX][NMAX], DP[NMAX];
struct Box
{
int X, Y, Z;
}V[NMAX];
int LSB(int X)
{
return (X & (X - 1)) ^ X;
}
void Update(int X, int Y, int Val)
{
for(int i = X; i <= N; i += LSB(i))
for(int j = Y; j <= N; j += LSB(j))
FT[i][j] = max(FT[i][j], Val);
}
void Erase(int X, int Y)
{
for(int i = X; i <= N; i += LSB(i))
for(int j = Y; j <= N; j += LSB(j))
FT[i][j] = 0;
}
int Query(int X, int Y)
{
int Ans = 0;
for(int i = X; i; i -= LSB(i))
for(int j = Y; j; j -= LSB(j))
Ans = max(Ans, FT[i][j]);
return Ans;
}
struct Comp
{
bool operator() (const Box &A, const Box &B) const
{
return A.X < B.X;
}
};
int main()
{
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
scanf("%i %i", &N, &T);
for(; T; T --)
{
for(int i = 1; i <= N; ++ i) scanf("%i %i %i", &V[i].X, &V[i].Y, &V[i].Z);
sort(V + 1, V + N + 1, Comp());
int Ans = 0;
for(int i = 1; i <= N; ++ i)
{
DP[i] = Query(V[i].Y - 1, V[i].Z - 1) + 1;
Ans = max(Ans, DP[i]);
Update(V[i].Y, V[i].Z, DP[i]);
}
for(int i = 1; i <= N; ++ i)
Erase(V[i].Y, V[i].Z);
printf("%i\n", Ans);
}
return 0;
}