Pagini recente » Cod sursa (job #275060) | Cod sursa (job #2480202) | Cod sursa (job #1896508) | Cod sursa (job #1469295) | Cod sursa (job #544635)
Cod sursa(job #544635)
#include<cstdio>
#include<algorithm>
using namespace std;
struct pct
{
int x,y,z;
};
const int N=3505;
pct a[N];
int n,aib[N][N];
bool comp(const pct &A,const pct &B)
{
return A.x<B.x;
}
void read()
{
for(int i=1;i<=n;i++)
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
}
void init()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
aib[i][j]=0;
sort(a+1,a+n+1,comp);
}
int bit(int x)
{
return (x&(-x));
}
int max(int x,int y)
{
return x>y?x:y;
}
int query(int x,int y)
{
int val=0,yi=y;
while(x)
{
y=yi;
while(y)
{
val=max(val,aib[x][y]);
y-=bit(y);
}
x-=bit(x);
}
return val;
}
void update(int x,int y,int val)
{
int yi=y;
while(x<=n)
{
y=yi;
while(y<=n)
{
aib[x][y]=max(aib[x][y],val);
y+=bit(y);
}
x+=bit(x);
}
}
void solve()
{
int sol=0;
for(int i=1;i<=n;i++)
{
int aux=query(a[i].y,a[i].z);
aux++;
sol=max(sol,aux);
update(a[i].y,a[i].z,aux);
}
printf("%d\n",sol);
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
int t;
scanf("%d%d",&n,&t);
while(t--)
{
read();
init();
solve();
}
return 0;
}