Cod sursa(job #834852)

Utilizator alexalghisiAlghisi Alessandro Paolo alexalghisi Data 15 decembrie 2012 14:35:23
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;

struct p{
    int a, b, c;
};

p dp[3505],v[3505];
bool intra(p cutie,p dest)
{
    return (cutie.a<dest.a && cutie.b<dest.b && cutie.c<dest.c);
}

struct cmp
{
    bool operator()(const p &x , const p &y)
    {
        if(x.a==y.a)
            {
                if(x.b==y.b)
                    return x.c<y.c;
                else
                    return x.b<y.b;
            }
        return x.a<y.a;
    }
};
int main()
{
    int n,t;
    ifstream f("cutii.in");
    ofstream g("cutii.out");
    f>>n>>t;
    for( ;t;--t)
    {
        memset(dp,0,sizeof(dp));
        int sz=0;

        for(int j=1;j<=n;++j)
            f>>v[j].a>>v[j].b>>v[j].c;

        sort(v+1,v+n+1,cmp());

         for(int j=1;j<=n;++j)
         {
              for(int k=sz;k>=0;k--)
                if(intra(dp[k],v[j]))
                {
                    if(k+1>sz)
                     {
                        ++sz;
                        dp[k+1]=v[j];
                     }
                     else
                        if(dp[k+1].a>=v[j].a && dp[k+1].b>=v[j].b && dp[k+1].c>=v[j].c)
                            dp[k+1]=v[j];
                    break;
                }
        }
        g<<sz<<"\n";
    }
    return 0;
}