Pagini recente » Cod sursa (job #2986835) | Cod sursa (job #2973894) | Cod sursa (job #1662877) | Cod sursa (job #1011842) | Cod sursa (job #292697)
Cod sursa(job #292697)
#include <fstream>
using namespace std;
ifstream f("cutii.in");
ofstream g("cutii.out");
int c[3503][4],k,n,i,j,l[3503],lm,mx,ii;
void swap(int x,int y)
{
int ax;
ax=c[x][1];
c[x][1]=c[y][1];
c[y][1]=ax;
ax=c[x][2];
c[x][2]=c[y][2];
c[y][2]=ax;
ax=c[x][3];
c[x][3]=c[y][3];
c[y][3]=ax;
}
void read()
{
for(j=1;j<=n;j++)
f>>c[j][1]>>c[j][2]>>c[j][3];
}
void qsort(int left,int right)
{
j=left-1;
for(i=left;i<=right;i++)
if(c[i][1]>=c[right][1])
swap((++j),i);
if(j-1>left)
qsort(left,j-1);
if(j+1<right)
qsort(j+1,right);
}
/*void sort()
{
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
{
if(c[i][1]<c[j][1])
swap(i,j);
/* else if(c[i][1]==c[j][1])
{
if(c[i][2]<c[j][2])
swap(i,j);
else if(c[i][2]==c[j][2])
{
if(c[i][3]<c[j][3])
swap(i,j);
}
}/
}
}*/
void dinamic()
{
l[1]=1;
lm=1;
for(i=2;i<=n;i++)
{
mx=0;
for(j=1;j<i;j++)
{
if(c[i][1]<c[j][1]&&c[i][2]<c[j][2]&&c[i][3]<c[j][3]&&mx<l[j])
mx=l[j];
}
l[i]=mx+1;
if(lm<l[i])
lm=l[i];
}
g<<lm<<endl;
}
int main()
{
f>>n>>k;
for(ii=1;ii<=k;ii++)
{
read();
qsort(1,n);
dinamic();
}
}