반응형
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BJ_S3_15649_N과M_1 {
static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder output = new StringBuilder();
static StringTokenizer tokens;
static int N,M;
public static void main(String[] args) throws IOException {
tokens = new StringTokenizer(input.readLine());
N = Integer.parseInt(tokens.nextToken());
M = Integer.parseInt(tokens.nextToken());
int [] choosed = new int [M];
boolean [] visited = new boolean[N];
permutation(M, choosed, visited);
////
System.out.println(output);
}
static void permutation(int choose, int[] choosed, boolean[] visited) {
if(choose == 0) {
for (int val : choosed) {
output.append(val).append(" ");
}
output.append("\n");
return;
}
for (int i = 0; i < N; i++) {
if(!visited[i]) {
visited[i]=true;
choosed[choosed.length - choose] = i+1;
permutation(choose-1, choosed, visited);
visited[i] = false;
}
}
}
}
반응형
'코딩테스트 > 백준문제' 카테고리의 다른 글
[Java] 백준_17478_재귀함수가뭔가요 (0) | 2021.02.08 |
---|---|
[Java] 백준_1244_스위치켜고끄기 (0) | 2021.02.08 |
[Java] 백준_2493_탑 (0) | 2021.02.08 |
[python 파이썬] 백준 1920번 : 수 찾기 (0) | 2020.11.29 |
[python 파이썬] 백준 10039번 : 평균 점수 (0) | 2020.11.09 |