import java.awt.*;
import java.util.*;
import java.io.*;
public class Main {
static int N;
static int S;
static ArrayList<Integer> list = new ArrayList<>();
static int[] re;
static int[] arr;
static boolean[] vi;
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());
int M = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
arr = new int[N];
vi = new boolean[N];
re = new int[M];
for(int i=0;i<N;i++){
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
dfs(N,M,0);
}
private static void dfs(int n, int m, int k) {
if(m==k){
for(int num:re){
//System.out.println("num "+num);
System.out.print(arr[num]+" ");
}
System.out.println();
return;
}
for(int i=0;i<n;i++) {
if(!vi[i]) {
vi[i] = true;
re[k] = i;
dfs(n, m, k + 1);
vi[i] = false;
}
}
}
}
수열 구하는 문제
여러 방식으로 다르게 조합할 수 있도록 연습!
오늘의 회고
- 우아한테크캠프 코딩테스트 겁 먹은거 치고 푼 문제가 있으니 앞으로도 꾸준히 하자
- 내일(4/14) 학습 예정 : 스프링부트 온라인 강의 듣기
'algorithm > 문제 풀이' 카테고리의 다른 글
99클럽 코테 스터디 16일차 TIL - 프로그래머스 신고 결과 받기 (0) | 2024.04.16 |
---|---|
99클럽 코테 스터디 14일차 TIL - 프로그래머스 JadenCase 문자열 만들기 (0) | 2024.04.14 |
99클럽 코테 스터디 12일차 TIL - 프로그래머스 연속된 부분 수열의 합 (0) | 2024.04.12 |
99클럽 코테 스터디 11일차 TIL - 백준 14888 (연산자 끼워넣기) (0) | 2024.04.11 |
99클럽 코테 스터디 10일차 TIL - 프로그래머스 이진 변환 반복하기 (0) | 2024.04.10 |