File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ package backjoon ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+ import java .util .StringTokenizer ;
7+
8+ public class _15649 {
9+ public static int [] arr ;
10+ public static boolean [] visit ;
11+ public static StringBuilder sb = new StringBuilder ();
12+
13+ public static void main (String [] args ) throws IOException {
14+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
15+ StringTokenizer st = new StringTokenizer (br .readLine ());
16+ // memory runtime
17+ int N = Integer .parseInt (br .readLine ());
18+ int M = Integer .parseInt (st .nextToken ());
19+
20+ arr = new int [M ];
21+ visit = new boolean [N ];
22+ dfs (N , M , 0 );
23+ System .out .println (sb );
24+ }
25+
26+ public static void dfs (int N , int M , int depth ) {
27+ if (depth == M ) {
28+ for (int val : arr ) {
29+ sb .append (val ).append (' ' );
30+ }
31+ sb .append ('\n' );
32+ return ;
33+ }
34+
35+ for (int i = 0 ; i < N ; i ++) {
36+ if (!visit [i ]) {
37+ visit [i ] = true ;
38+ arr [depth ] = i + 1 ;
39+ dfs (N , M , depth + 1 );
40+ visit [i ] = false ;
41+ }
42+ }
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments