結果
問題 |
No.698 ペアでチームを作ろう
|
ユーザー |
![]() |
提出日時 | 2019-08-26 20:15:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 1,000 ms |
コード長 | 1,223 bytes |
コンパイル時間 | 1,843 ms |
コンパイル使用メモリ | 169,800 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 02:07:51 |
合計ジャッジ時間 | 2,898 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; int bit_count(int n) { int cnt = 0; while (n != 0) { if (n % 2 == 1) cnt++; n >>= 1; } return cnt; } // まだ使っってないものがS ll power(int S, int n,vector<ll>& dp,const vector<int>& a) { if (dp[S] >= 0) return dp[S]; if (S == (1<<n)-1) return dp[S] = 0; ll res = 0; REP(i, n) { REP(j, n) { if (i == j) continue; // 既に使われている if ((S | (1 << i)) == S || (S | (1 << j)) == S) continue; res = max(res, power(S | (1 << i) | (1 << j), n, dp,a) + (a[i] ^ a[j])); } } return dp[S] = res; } int main() { int n; cin >> n; vector<ll> dp(1 << n,-1); vector<int> a(n); REP(i, n) { cin >> a[i]; } cout << power(0, n, dp, a) << endl; getchar(); getchar(); }