結果
| 問題 | No.698 ペアでチームを作ろう |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-29 09:30:32 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,330 bytes |
| 記録 | |
| コンパイル時間 | 2,210 ms |
| コンパイル使用メモリ | 76,916 KB |
| 実行使用メモリ | 46,080 KB |
| 最終ジャッジ日時 | 2024-09-15 20:09:47 |
| 合計ジャッジ時間 | 5,326 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 TLE * 1 -- * 9 |
ソースコード
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;
}
}
htensai