File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.BufferedReader ;
3+ import java.io.IOException ;
4+ import java.io.InputStreamReader ;
5+ import java.util.StringTokenizer ;
6+
7+ public class Main {
8+ private static final int N = 11 ;
9+ private static int [][] Scores = new int [N ][N ];
10+ private static boolean [] Used = new boolean [N ];
11+ private static int MaxSum = 0 ;
12+
13+ public static void main (String [] args ) throws IOException {
14+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
15+ int t = Integer . parseInt(br. readLine());
16+ while (t-- > 0 ){
17+ for (int i = 0 ; i < N ; i++ ) {
18+ StringTokenizer st = new StringTokenizer (br. readLine());
19+ for (int j = 0 ; j < N ; j++ ) {
20+ Scores [i][j] = Integer . parseInt(st. nextToken());
21+ }
22+ }
23+ Used = new boolean [N ];
24+ MaxSum = 0 ;
25+ dfs(0 , 0 );
26+ System . out. println(MaxSum );
27+ }
28+ }
29+
30+ private static void dfs (int pos , int currentSum ) {
31+ if (pos == N ) {
32+ if (currentSum > MaxSum ) {
33+ MaxSum = currentSum;
34+ }
35+ return ;
36+ }
37+ for (int player = 0 ; player < N ; player++ ) {
38+ if (Scores [player][pos] == 0 ) continue ;
39+ if (! Used [player]) {
40+ Used [player] = true ;
41+ dfs(pos + 1 , currentSum + Scores [player][pos]);
42+ Used [player] = false ;
43+ }
44+ }
45+ }
46+ }
47+
48+ ```
You can’t perform that action at this time.
0 commit comments