Skip to content

Commit e058fc9

Browse files
committed
issue #41 15651
1 parent 0386125 commit e058fc9

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/backjoon/_15651.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package backjoon;
2+
// https://www.acmicpc.net/problem/15651
3+
// N과 M (3)
4+
import java.io.BufferedReader;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.util.StringTokenizer;
8+
9+
public class _15651 {
10+
public static int[] arr;
11+
public static int N, M;
12+
public static StringBuilder sb = new StringBuilder();
13+
14+
public static void main(String[] args) throws IOException {
15+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
// memory 111924 runtime 372
18+
N = Integer.parseInt(st.nextToken());
19+
M = Integer.parseInt(st.nextToken());
20+
21+
arr = new int[M];
22+
dfs(0);
23+
System.out.println(sb);
24+
}
25+
26+
static void dfs(int depth){
27+
28+
if(depth == M){
29+
for(int v : arr){
30+
sb.append(v).append(" ");
31+
}
32+
sb.append("\n");
33+
return;
34+
}
35+
36+
for(int i=1; i<=N; i++){
37+
arr[depth] = i;
38+
dfs(depth+1);
39+
}
40+
}
41+
}
42+
/*
43+
INPUT
44+
4 2
45+
46+
OUTPUT
47+
1 1
48+
1 2
49+
1 3
50+
1 4
51+
2 1
52+
2 2
53+
2 3
54+
2 4
55+
3 1
56+
3 2
57+
3 3
58+
3 4
59+
4 1
60+
4 2
61+
4 3
62+
4 4
63+
*/

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