結果
| 問題 | No.519 アイドルユニット |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-01-26 16:44:24 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,082 bytes |
| 記録 | |
| コンパイル時間 | 1,903 ms |
| コンパイル使用メモリ | 83,928 KB |
| 実行使用メモリ | 790,856 KB |
| 最終ジャッジ日時 | 2026-03-08 13:03:18 |
| 合計ジャッジ時間 | 38,559 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 RE * 21 TLE * 10 MLE * 2 |
ソースコード
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