結果

問題 No.698 ペアでチームを作ろう
ユーザー xxxasdfghjkxxxasdfghjk
提出日時 2018-08-12 19:19:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 1,315 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 78,416 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 16:22:40
合計ジャッジ時間 1,397 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int N,DP[16384];
vector<int> sets(0);
int solve(int code){
  if(DP[code] != -1)
    return DP[code];
  int m = -1,back=code;
  
  if(code == 0)
    return 0;
  else{
    for(int i=0;i<N;i++){
      if((code >> i)&1){
        code = code ^ (1 << i);
        for(int j=i+1;j<N;j++){
          if((code >> j) & 1){
            code = code ^ (1 << j);
            m = max(m,(sets[i]^sets[j]) + solve(code));
            code = code ^ (1 << j);
          }
        }
      }
      code = back;
    }
  }
  return DP[back] = m;
}

int main()
{
  int A;
  cin >> N;
  REP(i,N){
    cin >> A;
    sets.push_back(A);
  }
  REP(i,(1 << 14))
    DP[i] = -1;
  sort(sets.begin(),sets.end());
  cout << solve((1 << N)-1) << endl;
  return 0;
}

0