🐣 알고리즘 삐약/💻 백준 삐약

86 삐약 : 백준 15652| N과 M (4) [바킹독| 백트래킹 |JAVA]

우주수첩 2024. 8. 14. 15:24
728x90

 

https://www.acmicpc.net/problem/15652

 

 

package BKD_0x0C_BackTracking;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class BOJ_15652 {
    static int N;
    static int M;
    static int[] arr;

    static void dfs(int depth,int at){
        if(depth==M){
            for(int val : arr){
                System.out.print(val+" ");
            }
            System.out.println();
            return;
        }
        for(int i=at;i<N;i++){
            arr[depth]=i+1;
            dfs(depth+1,i);
        }
        return;

    }

    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());
        M = Integer.parseInt(st.nextToken());

        arr = new int[M];
        dfs(0,0);
    }
}

 

728x90