Skip to content

Commit 407b270

Browse files
committed
[Silver III] Title: N과 M (1), Time: 1448 ms, Memory: 48560 KB -BaekjoonHub
1 parent 8bb5552 commit 407b270

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11

2-
32
import java.io.BufferedReader;
43
import java.io.IOException;
54
import java.io.InputStreamReader;
65
import java.util.StringTokenizer;
76

87
public 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
}

백준/Silver/15649. N과 M (1)/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
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

0 commit comments

Comments
 (0)