https://www.acmicpc.net/problem/15650
import java.util.*;
import java.io.*;
public class Main {
static int N, M;
static int[] arr;
static boolean[] selected;
static StringBuilder sb = new StringBuilder();
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
arr = new int[N + 1];
selected = new boolean[N + 1];
M = Integer.parseInt(st.nextToken());
for(int i = 1; i <= N; i++){
arr[i] = i;
}
combination(1, 0);
System.out.print(sb);
}
static void combination(int idx, int size) {
if (size == M) {
for(int i = 1; i <= N; i++){
if(selected[i]) sb.append(arr[i]).append(" ");
}
sb.append("\n");
return;
}
for(int i = idx; i <= N; i++){
if(selected[i]) continue;
selected[i] = true;
combination(i + 1, size + 1);
selected[i] = false;
}
}
}
배열 원소 입력 잘 받았나 확인
System.out.println(Arrays.toString(arr));