Skip to content

Commit 174d664

Browse files
authored
Merge pull request #1535 from AlgorithmWithGod/Seol-JY
[20251128] BOJ / G5 / 선발 명단 / 설진영
2 parents d4368d5 + f70aaf9 commit 174d664

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static int N = 11;
8+
static int[][] abilities;
9+
static boolean[] visited;
10+
static int maxAbility;
11+
12+
static void dfs(int position, int currentAbility) {
13+
if (position == N) {
14+
maxAbility = Math.max(maxAbility, currentAbility);
15+
return;
16+
}
17+
18+
for (int i = 0; i < N; i++) {
19+
if (!visited[i] && abilities[i][position] > 0) {
20+
visited[i] = true;
21+
dfs(position + 1, currentAbility + abilities[i][position]);
22+
visited[i] = false;
23+
}
24+
}
25+
}
26+
27+
public static void main(String[] args) throws IOException {
28+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
29+
StringTokenizer st;
30+
int T = Integer.parseInt(br.readLine());
31+
32+
for (int t = 0; t < T; t++) {
33+
abilities = new int[N][N];
34+
visited = new boolean[N];
35+
maxAbility = 0;
36+
37+
for (int i = 0; i < N; i++) {
38+
st = new StringTokenizer(br.readLine());
39+
for (int j = 0; j < N; j++) {
40+
abilities[i][j] = Integer.parseInt(st.nextToken());
41+
}
42+
}
43+
44+
dfs(0, 0);
45+
System.out.println(maxAbility);
46+
}
47+
}
48+
}
49+
50+
```

0 commit comments

Comments
 (0)