深搜
#include<stdio.h>
int n, p, len, cnt;
bool flag;
int num[1024];
struct{
int n, pos;
}tmp[1024];
bool isRepet(int s, int e){
for(int i = s + 1; i < e; i++)
if(num[i] == num[e]) return true;
return false;
}
void print(int len){
for(int i = 0; i < len - 1; i++)
printf("%d ",tmp[i].n);
printf("%d\n",tmp[len - 1].n);
}
void dfs(int dep, int pos){
if(cnt >= p)
return;
if(dep == len){
cnt ++;
flag = true;
print(len);
return;
}
for(int i = pos; i < n; i++){// i < n!
if(dep != 0 && tmp[dep-1].n <= num[i] || dep == 0){
if(dep == 0 && isRepet(-1, i))
continue;
if(dep != 0 && isRepet(tmp[dep - 1].pos, i))
continue;
tmp[dep].n = num[i];
tmp[dep].pos = i;
dfs(dep + 1, i + 1);
}
}
}
int main(){
while(~scanf("%d %d", &n, &p)){
for(int i = 0; i < n; i++)
scanf("%d", &num[i]);
cnt = 0;
for(int i = 1; i < n; i++){
flag = false;
len = i;
dfs(0,0);
if(cnt >= p || !flag)
break;
}
puts("");
}
return 0;
}