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