結果

問題 No.698 ペアでチームを作ろう
ユーザー hiro71687k
提出日時 2022-04-07 23:06:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 817 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 195,560 KB
最終ジャッジ日時 2025-01-28 15:39:37
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ll inf=1001001001001;
ll mod=1000000007;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll>dp(1<<n,-1);
    dp[0]=0;
    for (ll i = 0; i < (1<<n); i++)
    {
        if (dp[i]==-1)
        {
            continue;
        }
        for (ll j = 0; j < n; j++)
        {
            if (i&(1<<j))
            {
                continue;
            }
            for (ll k = j+1; k < n; k++)
            {
                if (i&(1<<k))
                {
                    continue;
                }
                dp[i+(1<<j)+(1<<k)]=max(dp[i+(1<<j)+(1<<k)],dp[i]+(a[j]^a[k]));
            }
        }
    }
    cout << dp[(1<<n)-1] << endl;
}
0