본문 바로가기
Algorithm & SQL/BAEKJOON

백준 JAVA 15651 N과 M(3)

by YoonJong 2022. 7. 26.
728x90
반응형

package BAEKJOON.Silver.Ⅲ;

import java.util.Scanner;

public class NO15651 {

    static int n;
    static int m;
    static int [] arr;
    static StringBuilder sb = new StringBuilder();

    public static void dfs(int depth){
        if(m == depth) {
            for (int i = 0; i < m; i++) {
                sb.append(arr[i]).append(" ");
            }
            sb.append("\n");
            return;
        }

        for (int i = 1; i <= n; i++) {
            arr[depth] = i;
            dfs(depth+1);
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();

        arr = new int [n];
        dfs(0);
        System.out.println(sb);
    }
}

 

728x90
반응형

'Algorithm & SQL > BAEKJOON' 카테고리의 다른 글

백준 JAVA 1697 숨바꼭질  (0) 2022.07.28
백준 JAVA 15650 N과 M(2)  (0) 2022.07.27
백준 JAVA 15649 N과 M(1)  (0) 2022.07.26
백준 JAVA 11866 요세푸스 문제0  (0) 2022.07.21
백준 JAVA 1026 보물  (0) 2022.07.19

댓글