Cod sursa(job #2518882)

Utilizator vlad082002Ciocoiu Vlad vlad082002 Data 6 ianuarie 2020 17:58:19
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <fstream>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

ifstream fin("cutii.in");
ofstream fout("cutii.out");

int n, t, res;
int dp[3510];
int x[3510], y[3510], z[3510], poz[3510];

bool cmp(int i, int j) {
    if (x[i] > x[j]) return 0;
    else if(x[i] == x[j]) {
        if(y[i] > y[j]) return 0;
        else if(y[i] == y[j]) {
            if(z[i] > z[j]) return 0;
            else return 1;
        }
        else return 1;
    }
    else return 1;
}

void solve() {
    while(t--) {
        for(int i = 1; i <= n; i++) {
            fin >> x[i] >> y[i] >> z[i];
            poz[i] = i;
        }

        sort(poz+1, poz+n+1, cmp);
        res = 0;

        for(int i = 1; i <= n; i++) {
            dp[i] = 1;
            for(int j = i-1; j >= 1; j--)
                if(x[i] > x[j] && y[i] > y[j] && z[i] > z[j] && dp[i] < dp[j]+1)
                    dp[i] = dp[j]+1;
            if(dp[i] > res) res = dp[i];
        }

        fout << res << '\n';
//        p.clear();
//        for(int i = 1; i <= n; i++)
//            cb(0, p.size()-1, i);
//
//        fout << p.size() << '\n';
    }
}

int main() {
    fin >> n >> t;
    solve();
}