-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboj_10974.java
41 lines (34 loc) · 971 Bytes
/
boj_10974.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package backtracking;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class boj_10974 {
static int N;
static boolean[] visited;
static int[] arr;
static StringBuilder sb=new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
N=Integer.parseInt(br.readLine());
arr=new int[N];
visited=new boolean[N];
dfs(0);
}
private static void dfs(int depth){
if(depth==N){
for(int i=0;i<N;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
return;
}
for(int i=0;i<N;i++){
if(!visited[i]){
visited[i]=true;
arr[depth]=i+1;
dfs(depth+1);
visited[i]=false;
}
}
}
}