Cod sursa(job #483637)

Utilizator blasterzMircea Dima blasterz Data 9 septembrie 2010 15:14:51
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
# include <fstream>
# include <cstdio>
# include <cstdio>
# include <algorithm>


  using namespace std;

  #define dim 8192
  char ax[dim];
  int pz;
  
  inline void cit (int &x)
  {
	  x = 0;
	  while (ax[pz] < '0' || ax[pz] > '9')
		  if (++pz == dim)
			  fread (ax, 1, dim, stdin), pz = 0;
		  
	while (ax[pz] >= '0' && ax[pz] <= '9')
	{
		x = x * 10 + ax[pz] - '0';
		if (++pz == dim)
			fread (ax, 1, dim, stdin), pz = 0;
	}
  }

  
    struct stu { 
		int x, y, z;
	};
	
    inline bool cmp(stu a, stu b){
		return a.z<b.z;
    }
	
	stu v[3510];
	int maxval[3501];
	
	int n, i, j, mx, a[3510], t;
	
	int main (){
		//ifstream f ("cutii.in");
		freopen ("cutii.in", "r", stdin);
		cit (n); cit (t);
		//f>>n>>t;
		ofstream g ("cutii.out");
		for (; t; --t){
    		for (i=1; i<=n; ++i)
				cit (v[i].x), cit (v[i].y), cit (v[i].z);//f>>v[i].x>>v[i].y>>v[i].z;
	    	sort (v+1, v+n+1, cmp);
    		mx=1;
	    	a[n]=1;
			for (i=1; i<=n; ++i) a[i]=1;
			maxval[n] = 1;
		    for (i=n-1; i; --i)
			{
			    for (j=i+1; j<=n; ++j){
					if (maxval[j] < a[i])
						break;
				    if (v[j].x>v[i].x && v[j].y>v[i].y && v[j].z>v[i].z && a[i]<a[j]+1){
					    a[i]=a[j]+1;
				    	if (mx<a[i]) mx=a[i];
    				}
	    		}
				maxval[i] = max (maxval[i + 1], a[i]);
			}
			g<<mx<<'\n';
		}
    	g.close ();
	    return 0;
	}