Pagini recente » Cod sursa (job #472661) | Cod sursa (job #131128) | Cod sursa (job #2866365) | Cod sursa (job #2844030) | Cod sursa (job #861230)
Cod sursa(job #861230)
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define NMax 3510
#define zeros(x) ( x&(x-1)^x )
using namespace std;
const char IN[]="cutii.in",OUT[]="cutii.out";
struct cutie{
int x,y,z;
bool operator<(cutie const &b) const{
return x<b.x;
}
} c[NMax];
int N,T;
int arb[NMax][NMax];
void update(int x,int y,int val)
{
for (;x<=N;x+=zeros(x))
for(int y2=y;y2<=N;y2+=zeros(y2))
arb[x][y2]=max(arb[x][y2],val);
}
int query(int x,int y){
int ret=0;
for (;x;x-=zeros(x))
for (int y2=y;y2;y2-=zeros(y2))
ret=max(ret,arb[x][y2]);
return ret;
}
int main()
{
int i,r,rez;
freopen(IN,"r",stdin);
scanf("%d%d",&N,&T);
freopen(OUT,"w",stdout);
while (T--)
{
rez=r=0;
memset(arb,0,sizeof(arb));
for (i=1;i<=N;++i)
scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].z);
sort(c+1,c+N+1);
for (i=1;i<=N;++i){
r=1+query(c[i].y,c[i].z);
rez=max(rez,r);
update(c[i].y,c[i].z,r);
}
printf("%d\n",rez);
}
fclose(stdout);
return 0;
}