Cod sursa(job #368773)

Utilizator vladiiIonescu Vlad vladii Data 25 noiembrie 2009 21:03:44
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

struct Puncte {
    int x;
    int y;
    int z;
} p[3501];

int cmp(Puncte a, Puncte b) {
    if(a.z!=b.z) {
         return a.z>b.z;
    }
}

int main() {
    fstream f1, f2;
    int n, t, i, j, k, x, y, z, maxi, dan;
    int l[3501];
    f1.open("cutii.in", ios::in);
    f2.open("cutii.out", ios::out);
    f1>>n>>t;
    for(i=1; i<=t; i++) {
         for(j=0; j<n; j++) {
              f1>>p[j].x>>p[j].y>>p[j].z;
         }
         sort(p, p+n, cmp);
         l[0]=1; dan=-1000;
         for(j=1; j<n; j++) {
              maxi=1;
              for(k=0; k<j; k++) {
                   if(p[k].x>p[j].x && p[k].y>p[j].y && p[k].z>p[j].z) {
                        if(maxi<l[k]+1) {
                             maxi=l[k]+1;
                        }
                   }
              }
              l[j]=maxi;
              if(l[j]>dan) {
                   dan=l[j];
              }
         }
         f2<<dan<<endl;
    }
    f1.close(); f2.close();
    return 0;
}