Pagini recente » Cod sursa (job #2780992) | Cod sursa (job #3171595) | Cod sursa (job #1429666) | Cod sursa (job #1931571) | Cod sursa (job #2644269)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
const short NMAX = 3501;
short aib[NMAX][NMAX],n;
struct cutie{short x, y, z;};
bool cmp(cutie a, cutie b){
return a.x<b.x || (a.x==b.x && (a.y<b.y || (a.y==b.y && a.z<b.z)));
}
short lastBit(short num){
return num&-num;
}
void insert2(short pos1, short pos2, short val){
while(pos2<NMAX){
aib[pos1][pos2]=max(aib[pos1][pos2],val);
pos2+=lastBit(pos2);
}
}
void insert(short pos1,short pos2, short val){
while(pos1<NMAX){
insert2(pos1,pos2,val);
pos1+=lastBit(pos1);
}
}
short getmax2(short pos1,short pos2){
short Max=0;
while(pos2){
Max=max(Max,aib[pos1][pos2]);
pos2-=lastBit(pos2);
}
return Max;
}
short getmax(short pos1,short pos2){
short Max=0;
while(pos1){
Max=max(Max,getmax2(pos1,pos2));
pos1-=lastBit(pos1);
}
return Max;
}
void tc(){
short dp[NMAX]{},ans=0;
cutie v[NMAX];
for(short i=0;i<n;i++){
fin>>v[i].x>>v[i].y>>v[i].z;
for(short j=0;j<n;j++)
aib[i+1][j+1]=0;
}
sort(v,v+n,cmp);
for(short i=0;i<n;i++){
dp[i]=getmax(v[i].y-1,v[i].z-1)+1;
insert(v[i].y,v[i].z,dp[i]);
ans=max(ans,dp[i]);
}
fout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false); fin.tie(0); fout.tie(0);
short k; fin>>n>>k; while(k--)
tc();
return 0;
}