실버 3
https://www.acmicpc.net/problem/15655
package 백트래킹;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class boj_15654 {
static StringBuilder sb = new StringBuilder();
static int n, m;
static boolean[] visit;
static int[] arr;
static int[] input;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
input = new int[n];
for(int i=0;i<n;i++){
input[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(input);
visit = new boolean[n];
arr = new int[m];
dfs(0,0);
System.out.println(sb);
}
private static void dfs(int depth, int start) {
if (depth == m) {
for (int val : arr) {
sb.append(val).append(" ");
}
sb.append("\n");
return;
}
for (int i = start; i < n; i++) {
if (!visit[i]) {
visit[i] = true;
arr[depth] = input[i];
dfs(depth + 1,i);
visit[i] = false;
}
}
}
}
압도적으로 감사드립니다