Pagini recente » Rating Razvan Alexandru Sandu (SKREFI) | Cod sursa (job #2634588) | Cod sursa (job #1015374) | Cod sursa (job #2416855) | Cod sursa (job #478333)
Cod sursa(job #478333)
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#define nmax 3502
using namespace std;
const char iname[] = "cutii.in";
const char oname[] = "cutii.out";
ifstream fin(iname);
ofstream fout(oname);
struct box
{
int x, y, z;
};
box cutie[nmax];
int N, T, i, j;
int AIB[nmax][nmax];
struct cmp
{
bool operator()(const box &a, const box &b)const
{
if(a.z <= b.z)
return 1;
return 0;
}
};
void update(int first, int second, int valoare)
{
int p = first;
int q = second;
for(;p <= N; p += p & -p)
for(; q <= N; q += q & -q)
if(valoare > AIB[p][q])
AIB[p][q] = valoare;
}
int query(int first, int second)
{
int p = first;
int q = second;
int mx = 0;
for(;p >= 1; p -= p & -p)
for(;q >= 1; q -= q & -q)
if(AIB[p][q] > mx)
mx = AIB[p][q];
return mx;
}
void erase(int first, int second)
{
int p = first;
int q = second;
for(; p <= N; p += p & -p)
for(; q <= N; q += q & - q)
AIB[p][q] = 0;
}
int main()
{
fin >> N >> T;
for(i = 1; i <= T; i ++)
{
for(j = 1; j <= N; j ++)
fin >> cutie[j].x >> cutie[j].y >> cutie[j].z;
sort(cutie + 1, cutie + N + 1, cmp());
int maxx = 0;
int sol = 0;
for(j = 1; j <= N; j ++)
{
sol = query(cutie[j].x, cutie[j].y);
update(cutie[j].x, cutie[j].y, sol + 1);
if(sol + 1 > maxx)
maxx = sol + 1;
}
fout << maxx << "\n";
for(j = 1; j <= N; j ++)
erase(cutie[j].x, cutie[j].y);
}
return 0;
}