Cod sursa(job #3186855)

Utilizator Dia3141Costea Diana Stefania Dia3141 Data 25 decembrie 2023 23:12:33
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>
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];
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++;
            swap(c[i],c[j]);
        }
    }
    swap(c[i+1],c[pivot]);
    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(c[i].x!=c[j].x&&c[i].y>c[j].y&&c[i].z>c[j].z&&d[j]+1>d[i]){
                d[i]=d[j]+1;
                if(maxim[j]<d[i])
                    j=0;
            }
        }
        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;
        quicksort(1,n);
        cout<<sclm()<<'\n';
    }
    return 0;
}