Skip to content

Commit 28dc189

Browse files
committed
issue #41 N과 M (1)
1 parent 16da70c commit 28dc189

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/backjoon/_15649.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package backjoon;
2-
2+
// https://www.acmicpc.net/problem/15649
3+
// N과 M (1)
34
import java.io.BufferedReader;
45
import java.io.IOException;
56
import java.io.InputStreamReader;
@@ -12,9 +13,9 @@ public class _15649 {
1213

1314
public static void main(String[] args) throws IOException {
1415
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
// memory 19912 runtime 156
1517
StringTokenizer st = new StringTokenizer(br.readLine());
16-
// memory runtime
17-
int N = Integer.parseInt(br.readLine());
18+
int N = Integer.parseInt(st.nextToken());
1819
int M = Integer.parseInt(st.nextToken());
1920

2021
arr = new int[M];
@@ -24,6 +25,7 @@ public static void main(String[] args) throws IOException {
2425
}
2526

2627
public static void dfs(int N, int M, int depth) {
28+
// arr배열의 길이(depth)가 M과 같다면 출력
2729
if (depth == M) {
2830
for (int val : arr) {
2931
sb.append(val).append(' ');
@@ -32,13 +34,32 @@ public static void dfs(int N, int M, int depth) {
3234
return;
3335
}
3436

37+
// 중복값 체크를 위한 visit배열
3538
for (int i = 0; i < N; i++) {
36-
if (!visit[i]) {
39+
if (!visit[i]) { // 사용여부판단
3740
visit[i] = true;
3841
arr[depth] = i + 1;
39-
dfs(N, M, depth + 1);
40-
visit[i] = false;
42+
dfs(N, M, depth + 1); // 재귀호출
43+
visit[i] = false; //하나의 재귀함수가 끝나면 false로 바꿔줘야 다시 i라는 숫자 사용가능
4144
}
4245
}
4346
}
4447
}
48+
/*
49+
INPUT
50+
4 2
51+
52+
OUTPUT
53+
1 2
54+
1 3
55+
1 4
56+
2 1
57+
2 3
58+
2 4
59+
3 1
60+
3 2
61+
3 4
62+
4 1
63+
4 2
64+
4 3
65+
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy