Pagini recente » Cod sursa (job #2786467) | Cod sursa (job #1760083) | Cod sursa (job #98517) | Cod sursa (job #1816768) | Cod sursa (job #1782882)
#include <iostream>
#include <fstream>
#include <algorithm>
#define NMAX 3501
using namespace std;
ifstream in("cutii.in");
ofstream out("cutii.out");
struct pct
{
int x,y,z;
};
pct a[NMAX];
int aib[NMAX][NMAX],n,t,x,y,z;
bool comp(pct a,pct b);
void afisare()
{
for(int i=1;i<=n;i++)
cout << a[i].x << " " << a[i].y << " " << a[i].z << endl;
cout << endl;
}
inline int lsb(int x)
{
return (x&(-x));
}
int read(int indexx,int y)
{
int sol=0;
for(;indexx>0;indexx-=lsb(indexx))
{
for(int indexy=y;indexy>0;indexy-=lsb(indexy))
{
sol = max(aib[indexx][indexy],sol);
}
}
return sol;
}
void update(int indexx,int y,int val)
{
for(;indexx<=n;indexx+=lsb(indexx))
{
for(int indexy=y;indexy<=n;indexy+=lsb(indexy))
{
aib[indexx][indexy] = max(aib[indexx][indexy],val);
}
}
}
void Delete(int x,int y)
{
for(int i = x;i<=n;i+=lsb(i))
{
for(int j=y;j<=n;j+=lsb(j))
{
aib[i][j] = 0;
}
}
}
int s,Max;
void solve()
{
sort(a+1,a+n+1,comp);
Max = 0;
for(int i=1;i<=n;i++)
{
s = read(a[i].y-1,a[i].z-1) + 1;
Max = max(Max,s);
update(a[i].y,a[i].z,s);
}
out << Max << "\n";
for(int i=1;i<=n;i++)
Delete(a[i].y,a[i].z);
// afisare();
}
int main()
{
in >> n >> t;
for(int k=0;k<t;k++)
{
for(int i=1;i<=n;i++)
{
in >> x >> y >> z;
a[i].x = x;a[i].y= y;a[i].z = z;
}
solve();
}
return 0;
}
bool comp(pct a,pct b)
{
if(a.x < b.x)
{
return true;
}
else if(a.x>b.x)
{
return false;
}
else
{
if(a.y < b.y)
{
return true;
}
else if(a.y>b.y)
{
return false;
}
else
{
if(a.z <= b.z)
{
return true;
}
else if(a.x>b.x)
{
return false;
}
}
}
}