結果

問題 No.519 アイドルユニット
ユーザー simansiman
提出日時 2022-03-04 10:51:08
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 970 bytes
コンパイル時間 2,808 ms
コンパイル使用メモリ 141,556 KB
実行使用メモリ 79,360 KB
最終ジャッジ日時 2024-07-18 08:08:55
合計ジャッジ時間 7,497 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int V[N][N];

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> V[i][j];
    }
  }

  int L = 1 << N;
  int dp[L];
  memset(dp, 0, sizeof(dp));
  int ans = 0;

  for (int i = 0; i < N / 2; ++i) {
    for (int mask = 0; mask < L; ++mask) {
      if (__builtin_popcount(mask) != 2 * i) continue;

      for (int j = 0; j < N; ++j) {
        if (mask >> j & 1) continue;
        for (int k = j + 1; k < N; ++k) {
          if (mask >> k & 1) continue;
          int nmask = mask | (1 << j) | (1 << k);
          dp[nmask] = max(dp[nmask], dp[mask] + V[j][k]);
          ans = max(ans, dp[nmask]);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0