Cod sursa(job #3149130)

Utilizator Alex_BerbescuBerbescu Alexandru Alex_Berbescu Data 6 septembrie 2023 15:33:33
Problema Cutii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.68 kb

#include <stdio.h>
#include<algorithm>

#define dim 3505
using namespace std;
struct box
{
    int x, y, z;
} v[dim];
int test_cases, n, maxi;
int best[dim];
 bool compare(box a, box b)
{
    if(a.x == b.x)
    {
        if(a.y == b.y)
        {
            if(a.z > b.z)
            {
                return 0;
            }
            else
            {
                return 1;
            }
        }
        else
        {
            if(a.y < b.y)
            {
                return a.y < b.y;
            }
            else
            {
                return 0;
            }
        }
    }
    else
    {
        if(a.x < b.x)
        {
            return a.x < b.x;
        }
        else
        {
            return 0;
        }
    }
}
 bool verif(box a, box b)
{
    if(a.x < b.x && a.y < b.y && a.z < b.z)
    {
        return 1;
    }
    return 0;
}
int main(int argc, char * argv[])
{
    freopen("cutii.in","r",stdin);
    freopen("cutii.out","w",stdout);
     scanf("%d %d\n",&n,&test_cases);
   for(int u = 1; u <= test_cases; ++u)
    {
        maxi = 0;
        for(int i = 1; i <= n; ++i)
        {
            scanf("%d %d %d\n",&v[i].x,&v[i].y,&v[i].z);
        }
        sort(v + 1, v + n + 1, compare);
        maxi = 0;
        for(int i = 1; i <= n; ++i)
        {
            best[i] = 1;
            for(int j = i - 1; j >= 1; --j)
            {
                if(best[j] + 1 > best[i] && verif(v[j], v[i]))
                {
                    best[i] = best[j] + 1;
                   if(best[i] > maxi)
                   {
                       maxi = best[i];
                   }
                }
            }
        }
       printf("%d\n",maxi);
    }
    return 0;
}