Cod sursa(job #309766)

Utilizator Andrei200Andrei200 Andrei200 Data 1 mai 2009 00:33:18
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.91 kb
#include <stdio.h>

long int gasit,i,j,n,m,l[3502],L[3502],h[3502],v[3502],x,ii,aux;

void down(int poz,int n){   
int t=poz;   
int c1,c2;   
c1 = t<<1;   
  
  if(c1 < n && v[c1] < v[c1 + 1])   
  c1++;   
  
  while(c1<=n && v[t] < v[c1]){   
  aux=v[t];   
  v[t]=v[c1];   
  v[c1]=aux;   
  t=c1;   
  c1 = t<<1;   
  
    if(c1 < n && v[c1] < v[c1 + 1])   
    c1++;   
  
  }   
  
}   
  
void up(int poz,int n){   
int c=poz,t;   
t=c>>1;   
  
   while(t && v[c] > v[t]){   
   aux=v[t];   
   v[t]=v[c];   
   v[c]=aux;  
aux=l[t];   
   l[t]=l[c];   
   l[c]=aux;   
aux=h[t];   
   h[t]=h[c];   
   h[c]=aux;   
aux=L[t];   
   L[t]=L[c];   
   L[c]=aux;      
   c=t;   
   t=c>>1;   
   }   
  
}   
  
  
  
void sort(){   
  
 for(i=2;i<=n;i++){   
 up(i,i);   
 }   
  
 for(i=n;i>1;i--){   
 aux=v[i];   
 v[i]=v[1];   
 v[1]=aux; 
 aux=l[i];   
   l[i]=l[1];   
   l[1]=aux;   
aux=h[i];   
   h[i]=h[1];   
   h[1]=aux;   
aux=L[i];   
   L[i]=L[1];   
   L[1]=aux;      
 
 down(1,i-1);   
 }   
}   



int intra(long int i, long int j)
{
 long int gasit=1;
 if (l[i]>l[j] && L[i]>L[j] && h[i]>h[j])
   gasit=0;
 return gasit;
}

int main()
{
 FILE *g=fopen("cutii.out","w");
 FILE *f=fopen("cutii.in","r");
 fscanf(f,"%ld %ld",&n,&m);
 for (ii=1;ii<=m;ii++)
    {
 for (i=1;i<=n;i++)
    fscanf(f,"%ld %ld %ld",&l[i],&L[i],&h[i]);

 for (i=1;i<=n;i++)
    v[i]=l[i]*L[i]*h[i];

 sort();
/*for (i=1;i<=n;++i)
	 printf("%d %d %d\n",l[i],L[i],h[i]);
printf("\n");*/
 for (i=1;i<=n+2;i++)
    v[i]=0;
 v[n]=1;
 long int max=0;
 for (i=n-1;i>=1;i--)
    {
     max=0;
     for (j=i+1;j<=n;j++)
if (v[j]>=max && intra(i,j)==0)
 {
  max=v[j];
  //break;
 }
     v[i]=max+1;
    }

 max=0;
 for (i=1;i<=n;i++)
    if (max<=v[i])
      max=v[i];

 fprintf(g,"%ld\n",max);
 }
 fclose(f);
 fclose(g);
 return 0;
}