Pagini recente » Cod sursa (job #3205093) | Cod sursa (job #893044) | Cod sursa (job #1776255) | Cod sursa (job #202695) | Cod sursa (job #292666)
Cod sursa(job #292666)
#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 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();
sort();
dinamic();
}
}