Cod sursa(job #1348641)

Utilizator akaprosAna Kapros akapros Data 19 februarie 2015 19:59:40
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,t,i,j,sol;
struct nod
{
    int x;
    int y;
    int z;
}v[3505];
int a[3505];
int cmp(const nod a,const nod b)
{
    if (a.x==b.x && a.y==b.y) return a.z<b.z;
    else if (a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}
int main()
{
    freopen("cutii.in","r",stdin);
    freopen("cutii.out","w",stdout);
    scanf("%d %d",&n,&t);
    while (t--){ sol=1;
    for (i=1;i<=n;i++)
    scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].z);
    sort(v+1,v+n+1,cmp);
    for (i=1;i<=n;i++)
    {
        a[i]=1;
        for (j=i-1;j>=1;j--)
        if (v[i].x>v[j].x && v[i].y>v[j].y && v[i].z>v[j].z)
        if (a[i]<a[j]+1) a[i]=a[j]+1;
        sol=max(sol,a[i]);
    }
    printf("%d\n",sol);
    }
    return 0;
}