結果

問題 No.519 アイドルユニット
ユーザー htensaihtensai
提出日時 2020-02-13 15:25:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 311 ms / 1,000 ms
コード長 1,111 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 77,504 KB
実行使用メモリ 109,832 KB
最終ジャッジ日時 2024-04-15 20:10:20
合計ジャッジ時間 10,378 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
109,440 KB
testcase_01 AC 304 ms
109,516 KB
testcase_02 AC 212 ms
59,776 KB
testcase_03 AC 180 ms
43,016 KB
testcase_04 AC 125 ms
39,976 KB
testcase_05 AC 123 ms
40,268 KB
testcase_06 AC 143 ms
41,100 KB
testcase_07 AC 143 ms
41,240 KB
testcase_08 AC 148 ms
41,568 KB
testcase_09 AC 147 ms
41,776 KB
testcase_10 AC 162 ms
41,900 KB
testcase_11 AC 180 ms
42,724 KB
testcase_12 AC 135 ms
41,292 KB
testcase_13 AC 177 ms
42,908 KB
testcase_14 AC 179 ms
42,672 KB
testcase_15 AC 176 ms
42,380 KB
testcase_16 AC 189 ms
42,744 KB
testcase_17 AC 184 ms
43,144 KB
testcase_18 AC 178 ms
42,512 KB
testcase_19 AC 173 ms
42,692 KB
testcase_20 AC 175 ms
42,748 KB
testcase_21 AC 178 ms
42,460 KB
testcase_22 AC 179 ms
42,600 KB
testcase_23 AC 179 ms
42,752 KB
testcase_24 AC 196 ms
45,980 KB
testcase_25 AC 194 ms
45,724 KB
testcase_26 AC 192 ms
46,276 KB
testcase_27 AC 200 ms
46,044 KB
testcase_28 AC 206 ms
46,172 KB
testcase_29 AC 311 ms
109,532 KB
testcase_30 AC 299 ms
109,832 KB
testcase_31 AC 305 ms
109,448 KB
testcase_32 AC 299 ms
109,696 KB
testcase_33 AC 138 ms
40,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[][] field;
    static int[] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        field = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                field[i][j] = sc.nextInt();
            }
        }
        dp = new int[1 << n];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        System.out.println(dfw((1 << n) - 1));
    }
    
    static int dfw(int key) {
        if (dp[key] != -1) {
            return dp[key];
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n - 1; i++) {
            if ((key & (1 << i)) == 0) {
                continue;
            }
            for (int j = i + 1; j < n; j++) {
                if ((key & (1 << j)) == 0) {
                    continue;
                }
                max = Math.max(max, dfw(key ^ ((1 << i) | (1 << j))) + field[i][j]);
            }
            break;
        }
        dp[key] = max;
        return max;
    }
}
0