Cod sursa(job #2068469)

Utilizator RazorBestPricop Razvan Marius RazorBest Data 17 noiembrie 2017 22:29:22
Problema Cutii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

struct cutie
{
    int x, y, z;

    bool operator<(const cutie & a) const
    {
        return x < a.x && y < a.y && z < a.z;
    }
};

void init_array(int v[], int n)
{
    for (int i = 0; i < n; i++)
        v[i] = 0;
}

int main()
{
    int t, n, dp[3501];
    cutie v[3501];

    fin >> n >> t;
    while (t)
    {
        int mx = 0;

        for (int i = 1; i <= n; i++)
            fin >> v[i].x >> v[i].y >> v[i].z;

        sort(v + 1, v + n + 1);
        init_array(dp, n + 1);
        for (int i = 1; i <= n; i++)
        {
            int j = i - 1;
            while (!(v[j] < v[i]) && j > 0) j--;
            mx = max(mx, dp[i] = dp[j] + 1);
        }
        fout << mx << '\n';
        t--;
    }
    return 0;
}