- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10971.java
More file actions
Latest commit
50 lines (35 loc) · 942 Bytes
/
Copy path10971.java
File metadata and controls
50 lines (35 loc) · 942 Bytes
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
42
43
44
45
46
47
48
49
50
importjava.util.*;
publicclassMain {
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
intn = sc.nextInt();
int[][] arr = newint[n][n];
for(inti=0; i<n; i++) {
for(intj=0; j<n; j++) {
arr[i][j] = sc.nextInt();
}
}
// 무조건 0에서 출발한다고 생각하고 1부터 끝까지 순회하면됨
check = newboolean[n];
check[0] = true;
go(arr, 1, 0, 0);
System.out.println(answer);
}
staticlonganswer = Long.MAX_VALUE;
staticboolean[] check;
publicstaticvoidgo(int[][] arr, intcnt, intcurrent, longsum) {
if(cnt == arr.length) {
if(arr[current][0] == 0)
return;
answer = Long.min(answer, sum+arr[current][0]);
return;
}
for(inti=1; i<arr.length; i++) {
if(check[i] || arr[current][i] == 0)
continue;
check[i] = true;
go(arr, cnt+1, i, sum+arr[current][i]);
check[i] = false;
}
}
}