Pagini recente » Cod sursa (job #2965117) | Cod sursa (job #3232692) | Cod sursa (job #819109) | Cod sursa (job #2982517) | Cod sursa (job #3186849)
#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;
}
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]){
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;
}