Pagini recente » Cod sursa (job #2975934) | Cod sursa (job #2266800) | Cod sursa (job #2278338) | Cod sursa (job #2272319) | Cod sursa (job #3269298)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
const int Nmax=3505;
int n;
int dp[Nmax];
int aib[Nmax][Nmax];
struct cutie
{
int x,y,z;
bool operator <(const cutie cmp)const
{
return x<cmp.x;
}
};
cutie c[Nmax];
int lsb(int x)
{
return x&(-x);
}
void update(int posy,int posz,int val)
{
for(int i=posy;i<=n;i+=lsb(i))
{
for(int j=posz;j<=n;j+=lsb(j))
{
aib[i][j]=max(aib[i][j],val);
}
}
}
void aibclear(int posy,int posz)
{
for(int i=posy;i<=n;i+=lsb(i))
{
for(int j=posz;j<=n;j+=lsb(j))
{
aib[i][j]=0;
}
}
}
int query(int posy,int posz)
{
int sol=0;
for(int i=posy;i>=1;i-=lsb(i))
{
for(int j=posz;j>=1;j-=lsb(j))
{
sol=max(sol,aib[i][j]);
}
}
return sol;
}
void solve()
{
for(int i=1;i<=n;i++)
{
fin>>c[i].x>>c[i].y>>c[i].z;
}
sort(c+1,c+n+1);
int prev=1;
int sol=0;
for(int i=1;i<=n;i++)
{
if(i!=1 && c[i].x!=c[i-1].x)
{
for(int j=prev;j<i;j++)
{
update(c[j].y,c[j].z,dp[j]);
}
prev=i;
}
dp[i]=1+query(c[i].y-1,c[i].z-1);
sol=max(sol,dp[i]);
}
fout<<sol<<'\n';
for(int i=1;i<=n;i++)
{
aibclear(c[i].y,c[i].z);
}
}
int main()
{
int t;
fin>>n>>t;
while(t--)
{
solve();
}
return 0;
}