말랑한 하루
[BAEKJOON] 15666 N과 M 12 (Java) 본문
반응형
[ 소스 코드 ]
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Scanner;
public class _15666_N과M_12 {
static final int MAX = 8;
static int N, M;
static int ary[];
static int temp[];
static StringBuilder sb = new StringBuilder();
static LinkedHashSet<String> h = new LinkedHashSet<String>();
static void permutation(int cnt) {
if (cnt == M) {
String input="";
for(int item : temp)
input+= item+" ";
if(h.add(input+"\n"))
sb.append(input+"\n");
return;
}
for (int i = (cnt==0?0:index); i < N; i++) {
temp[cnt] = ary[i];
permutation(cnt + 1);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
ary=new int[N];
temp=new int[M];
for(int i=0;i<N;i++)
ary[i] = sc.nextInt();
Arrays.sort(ary);
permutation(0);
System.out.print(sb);
sc.close();
}
}
반응형
'문제풀이 > BAEKJOON Online Judge' 카테고리의 다른 글
[BAEKJOON] 1260 DFS와 BFS (Java) (0) | 2021.01.26 |
---|---|
[BAEKJOON] 13023 ABCDE (Java) (0) | 2021.01.26 |
[BAEKJOON] 15665 N과 M 11 (Java) (0) | 2021.01.23 |
[BAEKJOON] 15664 N과 M 10 (Java) (0) | 2021.01.23 |
[BAEKJOON] 15663 N과 M 9 (Java) (0) | 2021.01.23 |
Comments