Cod sursa(job #2983449)

Utilizator gabriel10tm@gmail.comGabriel Marian [email protected] Data 22 februarie 2023 14:33:43
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>
using namespace std;
#if 1
#define cin fin
#define cout fout
ifstream fin("cutii.in");
ofstream fout("cutii.out");
#endif // 1
int n;
const int nmx = 3505;
typedef array<int,3> C;
vector<C> cut;
bool canFit(C c1, C c2){ // can box c1 fit in box c2 ?
    return c1[0] < c2[0] && c1[1] < c2[1] && c1[2] < c2[2];
}
void solve(){
    vector<int> dp(n,1);
    cut.clear();
    for(int i=0;i<n;i++){
        C c;
        cin >> c[0] >> c[1] >> c[2];
        cut.push_back(c);
    }

    sort(cut.begin(),cut.end());
    int res = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(canFit(cut[j],cut[i])){
                dp[i] = max(dp[i],dp[j]+1);
            }
        }
        res = max(res,dp[i]);
    }
    cout << res << "\n";
}

int main(){
    int t;
    cin >> n >> t;
    while(t--){
        solve();
    }
}