Cod sursa(job #434118)

Utilizator victor.ionescuIonescu Victor Cristian victor.ionescu Data 5 aprilie 2010 02:13:53
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
short N,T;
struct box { short x,y,z; } v[3510];
short aib[3510][3510];

inline bool cmp(const box &A,const box &B) { return (A.x<B.x); }
inline short bit(short x) { return (x&(x-1))^x; }
inline short max(short a,short b) { return a>b?a:b; }

void update_aib(short x,short y,short s){
	for (short cx=x;cx<=N;cx+=bit(cx))
		for (short cy=y;cy<=N;cy+=bit(cy))
			aib[cx][cy]=max(aib[cx][cy],s);
}

int get_aib(short x,short y){
	short rez=0;
	for (short cx=x;cx;cx-=bit(cx))
		for (short cy=y;cy;cy-=bit(cy))
			rez=max(rez,aib[cx][cy]);
	return rez;
}

void test_case(){
	memset(aib,0,sizeof(aib));

	for (short i=1;i<=N;++i) scanf("%d%d%d",&v[i].x,&v[i].y,&v[i].z);

	sort(v+1,v+N+1,cmp);

	for (short i=1;i<=N;++i) {
		short rez=get_aib(v[i].y-1,v[i].z-1)+1;
		update_aib(v[i].y,v[i].z,rez);
	}

	printf("%d\n",get_aib(N,N));
}



int main(){

	freopen("cutii.in","r",stdin);
	freopen("cutii.out","w",stdout);

	scanf("%d%d\n",&N,&T);
	for (short i=1;i<=T;++i) test_case();

	fclose(stdin);
	fclose(stdout);

	return 0;
}