結果

問題 No.698 ペアでチームを作ろう
ユーザー seaesaeseaesae
提出日時 2018-11-27 20:50:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 815 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 144,480 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 06:30:48
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repr(i,a,b) for(int i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x),end()
typedef long long ll;

//dp[msk]:集合mskの人がペアを組んでいるときの戦闘力の最大値
int N;
int A[14];
int dp[1<<14];

int main(){
    cin>>N;
    rep(i,0,N)cin>>A[i];
    
    rep(msk,0,1<<N){
        rep(a,0,N-1)rep(b,a+1,N){//二人の組を選ぶ
            if(!(msk & (1<<a)) && !(msk & (1<<b))){//集合mskにa,bが含まれないとき
                //dp漸化式:dp[msk+{a}+{b}]=max(dp[msk+{a}+{b}]dp[msk]+(A[a]とA[b]の排他的論理和))
                dp[msk+(1<<a)+(1<<b)]=max(dp[msk+(1<<a)+(1<<b)],dp[msk]+(A[a]^A[b]));
            }
        }
    }
    cout<<dp[(1<<N)-1]<<endl;
    
    return 0;
}
0