Cod sursa(job #1197332)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 11 iunie 2014 18:47:33
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

#define Nmax 3505

using namespace std;
int N,T;

struct cutii{
    int x,y,z;
};

cutii v[Nmax],DP[Nmax];
int lg;

void read()
{
    scanf("%d%d",&N,&T);
}

struct cmp
{
    bool operator()(const cutii A,const cutii B)const
    {
        if(A.x < B.x && A.y < B.y && A.z < B.z)
            return 1;
        return 0;
    }
};

bool mai_mare(cutii A,cutii B)
{
    if(!(A.x < B.x && A.y < B.y && A.z < B.z))
        return 1;
    return 0;
}

void R()
{
    for(int i = 1; i <= N; ++i)
        scanf("%d%d%d",&v[i].x,&v[i].y,&v[i].z);
}

void solve()
{
    lg = 0;
    memset(DP,0,sizeof(DP));
    for(int i = 1; i <= N; ++i)
    {
        int pz = lower_bound(DP+1,DP+lg+1,v[i],cmp()) - DP;
        if(mai_mare(DP[pz], v[i]) )
            DP[pz] = v[i];
        if(pz > lg)
        {
            ++lg;
            DP[pz] = v[i];
        }
    }
    printf("%d\n",lg);
}

int main()
{
    freopen("cutii.in","r",stdin);
    freopen("cutii.out","w",stdout);

    read();
    for(int i = 1; i <= T; ++i){
        R();
        solve();
    }
    return 0;
}