Cod sursa(job #1172592)

Utilizator balakraz94abcd efgh balakraz94 Data 17 aprilie 2014 18:38:51
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <cstdio>
#include <algorithm>
using namespace std;

#define nMax 3505

struct Cutie {
    int x, y, z;
    bool operator < (const Cutie &that)const{
		if(x != that.x)
            return x < that.x;
		if(y != that.y)
            return y < that.y;
        return z < that.z;
    }
};


Cutie C[nMax];

int DP[nMax];

int N, T, BEST;


inline bool itFits(const Cutie &A, const Cutie &B){
	return A.x < B.x && A.y < B.y && A.z < B.z;
}

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

    for(scanf("%d %d", &N, &T); T; -- T){
        for(int i = 0; i < N; ++ i)
            scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].z);

        sort(C, C + N);

        BEST = 1;
        for(int i = 0; i < N; ++ i){
            DP[i] = 1;
            for(int j = 0; j < i; ++ j)
                if(itFits(C[j], C[i]) && DP[j] + 1 > DP[i])
                    DP[i] = DP[j] + 1;

            BEST = max(BEST, DP[i]);
        }

        printf("%d\n", BEST);
    }

    fclose(stdin);
    fclose(stdout);

    return 0;
}