結果

問題 No.698 ペアでチームを作ろう
ユーザー htensaihtensai
提出日時 2020-01-29 09:30:32
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,330 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 74,908 KB
実行使用メモリ 52,432 KB
最終ジャッジ日時 2023-10-14 00:18:25
合計ジャッジ時間 5,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,612 KB
testcase_01 AC 43 ms
49,440 KB
testcase_02 AC 45 ms
49,236 KB
testcase_03 AC 43 ms
49,092 KB
testcase_04 AC 69 ms
52,432 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static int n;
    static int[][] dp;
    static int[] scores;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        String[] line = br.readLine().split(" ", n);
        scores = new int[n];
        for (int i = 0; i < n; i++) {
            scores[i] = Integer.parseInt(line[i]);
        }
        dp = new int[n / 2 + 1][(int)(Math.pow(2, n))];
        System.out.println(dfw(n / 2, (int)(Math.pow(2, n)) - 1));
    }
    
    static int dfw(int idx, int key) {
        if (idx == 0) {
            return 0;
        }
        if (dp[idx][key] != 0) {
            return dp[idx][key];
        }
        int max = 0;
        for (int i = 0; i < n - 1; i++) {
            int x = (int)(Math.pow(2, i));
            if ((key & x) == 0) {
                continue;
            }
            for (int j = i + 1; j < n; j++) {
                int y = (int)(Math.pow(2, j));
                if ((key & y) == 0) {
                    continue;
                }
                max = Math.max(max, dfw(idx - 1, key ^ (x | y)) + (scores[i] ^ scores[j]));
            }
        }
        dp[idx][key] = max;
        return max;
    }
}
0