結果
| 問題 | 
                            No.519 アイドルユニット
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tenten
                         | 
                    
| 提出日時 | 2021-01-26 16:44:24 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,082 bytes | 
| コンパイル時間 | 2,546 ms | 
| コンパイル使用メモリ | 78,048 KB | 
| 実行使用メモリ | 121,588 KB | 
| 最終ジャッジ日時 | 2024-06-23 15:55:35 | 
| 合計ジャッジ時間 | 6,730 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 1 -- * 33 | 
ソースコード
import java.util.*;
public class Main {
    static int[][] matrix;
    static HashMap<Integer, Integer> dp = new HashMap<>();
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        matrix = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrix[i][j] = sc.nextInt();
            }
        }
        dp.put(0, 0);
        System.out.println(dfw((1 << n) - 1));
    }
    
    static int dfw(int mask) {
        if (dp.containsKey(mask)) {
            return dp.get(mask);
        }
        int max = 0;
        for (int i = 0; i < n - 1; i++) {
            if ((mask & (1 << i)) == 0) {
                continue;
            }
            for (int j = i + 1; j < n; j++) {
                if ((mask & (1 << j)) == 0) {
                    continue;
                }
                max = Math.max(max, matrix[i][j] + dfw((mask ^ (1 << i)) ^ (1 << j)));
            }
        }
        dp.put(mask, max);
        return max;
    }
}
            
            
            
        
            
tenten