Mai intai trebuie sa te autentifici.
Cod sursa(job #2172169)
Utilizator | Data | 15 martie 2018 15:24:56 | |
---|---|---|---|
Problema | Cutii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.63 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
const int NMAX = 3500;
struct cutie
{
int x;
int y;
int z;
cutie()
{
x = 0;
y = 0;
z = 0;
}
cutie(int _x, int _y, int _z)
{
x = _x;
y = _y;
z = _z;
}
bool operator < (const cutie &arg) const
{
return (x < arg.x && y < arg.y & z < arg.z);
}
};
int n, teste, lungime;
int indice[NMAX], father[NMAX];
cutie v[NMAX];
int bs(int ind)
{
int st = 1, dr = n, mijl, sol = 0;
while (st <= dr)
{
mijl = (st + dr) / 2;
if (v[indice[mijl]] < v[ind])
{
sol = mijl;
st = mijl + 1;
}
else
dr = mijl - 1;
}
return sol + 1;
}
void build_dp()
{
lungime = 1;
indice[1] = 1;
for (int i = 2; i <= n; ++i)
if (v[indice[lungime]] < v[i])
{
++lungime;
indice[lungime] = i;
father[i] = indice[lungime - 1];
}
else
{
int poz = bs(i);
indice[poz] = i;
father[i] = indice[poz - 1];
}
}
void read()
{
int x, y, z;
for (int i = 1; i <= n; ++i)
{
fin >> x >> y >> z;
v[i] = cutie(x, y, z);
}
sort(v + 1, v + n + 1);
}
int main()
{
fin >> n >> teste;
while (teste--)
{
read();
build_dp();
fout << lungime << '\n';
}
return 0;
}