Pagini recente » Cod sursa (job #184422) | Cod sursa (job #2982391) | Cod sursa (job #1476844) | Cod sursa (job #2868951) | Cod sursa (job #3186852)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
int n,t,i,d[3502],maxim[3502];
struct cub{
int x,y,z;
}c[3502];
bool cmp(cub a,cub b){
if(a.x==b.x){
if(a.y==b.y)
return a.z>b.z;
return a.y>b.y;
}
return a.x<b.x;
}
bool verif(int i,int j){ //bag cutia j in cuita i
return c[i].y>c[j].y&&c[i].z>c[j].z;
}
void quicksort(int st,int dr){
if(st<dr){
int pivot=dr,i=st-1;
for(int j=st;j<dr;j++){
if(c[j].x<c[pivot].x){
i++;
cub aux=c[i];
c[i]=c[j];
c[j]=aux;
}
}
cub aux=c[pivot];
c[pivot]=c[i+1];
c[i+1]=aux;
pivot=i+1;
quicksort(st,pivot-1);
quicksort(pivot+1,dr);
}
}
int sclm(){
d[1]=1,maxim[1]=1;
for(int i=2;i<=n;i++){
d[i]=1;
for(int j=i-1;j>0;j--){
if(verif(i,j)&&d[j]+1>d[i]&&c[i].x!=c[j].x){
d[i]=d[j]+1;
}
if(maxim[j]<d[i])
break;
}
maxim[i]=max(maxim[i-1],d[i]);
}
return maxim[n];
}
int main()
{
cin>>n>>t;
while(t--){
for(i=1;i<=n;i++)
cin>>c[i].x>>c[i].y>>c[i].z;
sort(c+1,c+n+1,cmp);
cout<<sclm()<<'\n';
}
return 0;
}