#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<stack>
using namespace std;
int graph[35][35];
bool start;
int arr[30][10];
int length[35];
bool compare(int i,int j,int n)
{
for(int t=0;t<n;t++)
{
if(arr[i][t]>=arr[j][t])
return false;
}
return true;
}
int search(int i,int k)
{
if(length[i]!=-1)
return length[i];
length[i]=1;
int &final=length[i];
for(int j=0;j<k;j++)
{
if(graph[i][j])
{
int t=search(j,k)+1;
if(t>final)
{
final=t;
}
}
}
return final;
}
void Print_length(int index,int k)
{
if(start)
{
printf("%d",index+1);
start=false;
}
else
{
printf(" %d",index+1);
}
for(int j=0;j<k;j++)
{
if(graph[index][j]&&length[index]==length[j]+1)
{
Print_length(j,k);
break;
}
}
}
int main()
{
int k,n;
while(scanf("%d %d",&k,&n)!=EOF)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<n;j++)
scanf("%d",&arr[i][j]);
sort(arr[i],arr[i]+n);
}
memset(graph,0,sizeof(graph));
for(i=0;i<k;i++)
{
for(j=i+1;j<k;j++)
{
if(compare(i,j,n))
{
graph[i][j]=1;
}
else if(compare(j,i,n))
{
graph[j][i]=1;
}
}
}
memset(length,-1,sizeof(length));
int final=-1;
int position;
for(i=0;i<k;i++)
{
int temp=search(i,k);
if(temp>final)
{
final=temp;
position=i;
}
}
printf("%d\n",final);
start=true;
Print_length(position,k);
printf("\n");
}
return 0;
}
05-13
433
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-25
448
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-15
08-15