문제
https://www.acmicpc.net/problem/15664
코드
import java.util.*;
import java.io.*;
class Main {
static int arr [];
static int answer[];
static int n, m;
static StringBuilder sb = new StringBuilder();
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
arr = new int [n];
answer = new int [m];
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
back(0,0);
System.out.print(sb);
}
static void back(int start, int depth) {
if(depth == m) {
for(int i=0;i<m;i++) {
sb.append(answer[i]+" ");
}
sb.append("\n");
return;
}
int temp = 0;
for(int i=start;i<n;i++) {
if(temp != arr[i]) {
answer[depth] = arr[i];
temp = arr[i];
back(i+1, depth+1);
}
}
}
}