Cod sursa(job #998478)

Utilizator Mihai22eMihai Ionut Enache Mihai22e Data 17 septembrie 2013 09:54:16
Problema Cutii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <algorithm>
using namespace std;

const int MAX_N = 3502;

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

int N, T;
int dp[MAX_N];
box v[MAX_N];

inline bool box_cmp(box a, box b) {
    return (a.x < b.x && a.y < b.y && a.z < b.z);
}

int main() {
    ifstream f("cutii.in");
    ofstream g("cutii.out");

    f >> N >> T;
    while(T--) {
        for(int i = 1; i <= N; ++i)
            f >> v[i].x >> v[i].y >> v[i].z;

        sort(v+1, v+N+1, box_cmp);
        int sol = 0;
        for(int i = 1; i <= N; ++i) {
            dp[i] = 0;
            for(int j = 1; j < i; ++j)
                if(box_cmp(v[j], v[i]) && dp[j] > dp[i])
                    dp[i] = dp[j];
            ++dp[i];
            sol = max(sol, dp[i]);
        }

        g << sol << "\n";
    }

    f.close();
    g.close();

    return 0;
}