Cod sursa(job #1050649)

Utilizator AdrianaMAdriana Moisil AdrianaM Data 8 decembrie 2013 21:53:44
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include <fstream>
#include <algorithm>
using namespace std;

ifstream is("cutii.in");
ofstream os("cutii.out");

struct ceva{
    int x, y, z;
}c[3500];

int d[3500];
int n, t;
int maxim;

bool COMP(const ceva& a, const ceva& b);
bool OK(ceva a, ceva b);

int main()
{
    is >> n >> t;
    for ( int k = 1; k <= t; ++k )
    {
        for ( int j = 1; j <= n; ++j )
            is >> c[j].x >> c[j].y >> c[j].z;
        sort(c + 1, c + n + 1, COMP);
        //for ( int j = 1; j <= n; ++j )
            //os << c[j].x << " " << c[j].y << " " << c[j].z << "\n";
        maxim = 0;
        for ( int i = 1; i <= n; ++i )
        {
            d[i] = 1;
            for ( int j = 1; j < i; ++j )
            {
                if ( OK(c[j], c[i]) && d[j] + 1 > d[i] )
                    d[i] = d[j] + 1;
                if ( d[i] > maxim )
                    maxim = d[i];
            }
        }
        os << maxim << "\n";
    }
    is.close();
    os.close();
    return 0;
}

bool COMP(const ceva& a, const ceva& b)
//bool COMP(const int& a, const int& b)
{
    if ( a.x < b.x )
        return true;
    if ( a.x > b.x )
        return false;
    if ( a.y < b.y )
        return true;
    if ( a.y > b.y )
        return false;
    if ( a.z > b.z )
        return false;
}

bool OK(ceva a, ceva b)
{
    if ( a.x < b.x && a.y < b.y && a.z < b.z )
        return true;
    return false;
}