結果

問題 No.698 ペアでチームを作ろう
ユーザー alexara1123alexara1123
提出日時 2019-09-26 14:18:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 1,118 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 93,976 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 15:21:57
合計ジャッジ時間 1,713 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
ll MOD = 1000000007;
//ll INF = 1LL << 60;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}
int a[15], dp[1 << 15];
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);

   int n;
   cin >> n;
   for(int i=0; i < n; i++)
      cin >> a[i];

   for(int i=0; i < (1 << n); i++){
      for(int p=0; p < n; p++){
         for(int q=p+1; q < n; q++){
            if (!(i & (1 << p)) && !(i & (1 << q)))//集合iがpとqを除いた集合だった場合
            {
                  dp[i + (1 << p) + (1 << q)] = max(dp[i + (1 << p) + (1 << q)], dp[i] + (a[p] ^ a[q]));
            }
         }
      }
   }

   cout << dp[(1 << n) - 1] << endl;
}
0