Pagini recente » Cod sursa (job #167903) | Cod sursa (job #733282) | Cod sursa (job #333903) | Cod sursa (job #460276) | Cod sursa (job #641988)
Cod sursa(job #641988)
#include <cstdio>
#include <algorithm>
#define NMax 3505
using namespace std;
typedef struct
{
int X, Y, Z, V;
}
Box;
int N, S, DP[NMax];
Box B[NMax];
inline int Max (int a, int b)
{
if (a>b)
{
return a;
}
return b;
}
inline bool Compare (Box a, Box b)
{
if (a.V<b.V)
{
return true;
}
if (a.V>b.V)
{
return false;
}
if (a.X<b.X)
{
return true;
}
if (a.X>b.X)
{
return false;
}
if (a.Y<b.Y)
{
return true;
}
if (a.Y>b.Y)
{
return false;
}
if (a.Z<b.Z)
{
return true;
}
return false;
}
void Read ()
{
for (int i=1; i<=N; ++i)
{
scanf ("%d %d %d", &B[i].X, &B[i].Y, &B[i].Z);
B[i].V=B[i].X*B[i].Y*B[i].Z;
}
sort (B+1, B+N+1, Compare);
}
void LIS ()
{
for (int i=1; i<=N; ++i)
{
DP[i]=1;
for (int j=i-1; j>0; --j)
{
if (B[j].V<=B[i].V and B[j].X<=B[i].X and B[j].Y<=B[i].Y and B[j].Z<=B[i].Z)
{
DP[i]=Max (DP[i], DP[j]+1);
}
}
S=Max (S, DP[i]);
}
}
void Print ()
{
printf ("%d\n", S);
}
int main()
{
freopen ("cutii.in", "r", stdin);
freopen ("cutii.out", "w", stdout);
int T;
scanf ("%d %d", &N, &T);
for (; T>0; --T)
{
Read ();
S=0;
LIS ();
Print ();
}
return 0;
}