結果
問題 |
No.698 ペアでチームを作ろう
|
ユーザー |
![]() |
提出日時 | 2020-01-29 09:32:04 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 142 ms / 1,000 ms |
コード長 | 1,349 bytes |
コンパイル時間 | 2,223 ms |
コンパイル使用メモリ | 77,172 KB |
実行使用メモリ | 39,436 KB |
最終ジャッジ日時 | 2024-09-15 20:10:12 |
合計ジャッジ時間 | 3,735 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
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])); } break; } dp[idx][key] = max; return max; } }