Cod sursa(job #2211246)

Utilizator vladth11Vlad Haivas vladth11 Data 9 iunie 2018 17:03:37
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
struct cutie{
    int x,y,z;
}v[3501];
bool regula(cutie a,cutie b){
     return (a.z < b.z);
}
int a[3501];
int main()
{
    int n,i,j,k,t;
    cin >> n >> t;

    for(k = 0;k < t;k++){
    for(i = 1;i <= n;i++){
        cin >> v[i].x >> v[i].y >> v[i].z;
    }
    sort(v+1,v+n+1,regula);
        int max = 1;
        for(i = 1;i <= n;i++){
            a[i] = 1;
        }
        for(i = n-1;i > 0;i--){
            for(j = i+1;j <= n;j++){
                if(v[j].x > v[i].x && v[j].y > v[i].y && v[j].z > v[i].z && a[i] < a[j] + 1){
                    a[i] = a[j] + 1;
                    if(a[i] > max)
                        max = a[i];
                }
            }
        }
        cout << max << "\n";
    }

    return 0;
}