Cod sursa(job #300093)

Utilizator crawlerPuni Andrei Paul crawler Data 7 aprilie 2009 11:22:35
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <stdio.h>
#include <stdlib.h>
#include <string>

using namespace std;

#define Nmax 3504
#define fin "cutii.in"
#define fout "cutii.out"
#define x first
#define y second.first
#define z second.second
#define all(x) x+1,x+(n+1)
#define FOR(i,a,b) for(i=(a);i<=(b);++i)
#define cmp(i,j) ((c[i].y > c[j].y) && (c[i].z > c[j].z))
#define Dim 10000 

char buf[Dim];
int poz = 0;

void cit(int &x)
{
     x=0;
     while (buf[poz]<'0'){
           poz++;
           if (poz==Dim) fread(buf, 1, Dim, stdin), poz=0;
     }
     while (buf[poz]>='0'){
           x=x*10+buf[poz++]-'0';
           if (poz==Dim) fread(buf, 1, Dim, stdin), poz=0;
     }
}

pair< int , pair<int,int> >  c[Nmax];

int x[Nmax], best[Nmax];

int main()
 {
   freopen(fin,"r",stdin);
   freopen(fout,"w",stdout);

   register int n,t,i,j, Max,sol;

   cit(n);cit(t);

   srand(time(0));

   do
    {
     --t;
     
     FOR(i,1,n)
      {
       cit(c[i].x);cit(c[i].y);cit(c[i].z);
      }

     sort(all(c));

     sol = 0;
     x[0] = 0;
     best[0] = 1;

     FOR(i,1,n)
      {
       Max = 0;

       for(j=i-1;j>0;--j)
        {
         if(cmp(i,j) && (x[j]>=Max))
          Max = x[j]+1;
         if(best[j]<Max)
          break;
        }

       if(Max == 0) Max = 1;

       x[i] = Max;
       
       best[i] = max(best[i-1],x[i]);
       
       if(sol < Max)
        sol = Max;
      }
     
     printf("%d\n", sol);

    }while(t);

   return 0;
 }