File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 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+ */
You can’t perform that action at this time.
0 commit comments