File tree Expand file tree Collapse file tree
백준/Silver/15649. N과 M (1) Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11
2-
32import java .io .BufferedReader ;
43import java .io .IOException ;
54import java .io .InputStreamReader ;
65import java .util .StringTokenizer ;
76
87public class Main {
98
10- static boolean v [];
11- static int arr [];
9+ static boolean [] v ;
10+ static int [] result ;
11+ static int N ,M ;
1212 public static void main (String [] args ) throws IOException {
1313
1414 BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
1515 StringTokenizer st = new StringTokenizer (br .readLine ());
16+ N = Integer .parseInt (st .nextToken ());
17+ M = Integer .parseInt (st .nextToken ());
1618
17- int N = Integer .parseInt (st .nextToken ());
18- int M = Integer .parseInt (st .nextToken ());
1919 v = new boolean [N +1 ];
20- arr = new int [M ];
21- DFS (0 ,M ,N );
22-
23-
20+ result = new int [M ];
2421
22+ DFS (0 );
2523
2624 }
27- public static void DFS (int depth , int M , int N ){
25+ public static void DFS (int depth ){
2826 if (depth == M ){
29- //출력
3027 for (int i = 0 ; i < M ; i ++) {
31- System .out .print (arr [i ] + " " );
28+ System .out .print (result [i ] + " " );
3229 }
33- System .out .println ();
3430 return ;
3531 }
32+
3633 for (int i = 1 ; i <= N ; i ++) {
3734 if (!v [i ]){
3835 v [i ] = true ;
39- arr [depth ] = i ;
40- DFS (depth +1 , M , N );
36+ result [depth ] = i ;
37+ DFS (depth +1 );
4138 v [i ] = false ;
4239 }
4340 }
44-
4541 }
4642
4743}
Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 63792 KB, 시간: 1692 ms
7+ 메모리: 48560 KB, 시간: 1448 ms
88
99### 분류
1010
1111백트래킹
1212
1313### 제출 일자
1414
15- 2025년 3월 22일 17:21:00
15+ 2025년 3월 22일 18:23:37
1616
1717### 문제 설명
1818
You can’t perform that action at this time.
0 commit comments