728x90
https://www.acmicpc.net/problem/15650
package BKD_0x0C_BackTracking;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_15650 {
static int N;
static int M;
static int[] arr;
static void dfs(int at, int depth){
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(i+1,depth+1);
}
}
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);
}
}
이전 문제
2024.08.13 - [🐣 알고리즘 삐약/💻 백준 삐약] - 83 삐약 : 백준 15649| N과 M (1) [바킹독| 백트래킹 |JAVA]
와 다르게 방문 여부를 파악하는 배열이 없다.
이유인 오름차순의 수열만 취급하기 때문에
현재 위치해 있는 수 보다 큰 수는 당연히 방문 하지 않았기에 해당 배열을 사용하지 않는다.
728x90
'🐣 알고리즘 삐약 > 💻 백준 삐약' 카테고리의 다른 글
87 삐약 : 백준 15654| N과 M (5) [바킹독| 백트래킹 |JAVA] (0) | 2024.08.14 |
---|---|
86 삐약 : 백준 15652| N과 M (4) [바킹독| 백트래킹 |JAVA] (0) | 2024.08.14 |
83 삐약 : 백준 15649| N과 M (1) [바킹독| 백트래킹 |JAVA] (0) | 2024.08.13 |
82 삐약 : 백준 13458| 시험감독 [삼성 SW 역량테스트|JAVA] (0) | 2024.08.08 |
81 삐약 : 백준 1149| RGB거리 [바킹독 문제 풀이|DP|JAVA] (0) | 2024.06.19 |