結果

問題 No.519 アイドルユニット
コンテスト
ユーザー yuppe19 😺
提出日時 2017-07-01 14:54:34
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 52 ms / 1,000 ms
コード長 723 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,439 ms
コンパイル使用メモリ 170,876 KB
実行使用メモリ 69,048 KB
最終ジャッジ日時 2026-03-08 16:12:15
合計ジャッジ時間 2,748 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
main.cpp:10:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |       scanf("%d", &F[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
using namespace std;

int main(void) {
  int n; scanf("%d", &n);
  vector<vector<int>> F(n, vector<int>(n)); // F[n][n]
  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) {
      scanf("%d", &F[i][j]);
    }
  }
  vector<int> dp(1<<n, -1); // dp[1<<n]
  dp[0] = 0;
  for(int mask=0; mask<1<<n; ++mask) {
    if(dp[mask] == -1) { continue; }
    for(int i=0; i<n; ++i) {
      if(mask >> i & 1) { continue; }
      for(int j=i+1; j<n; ++j) {
        if(mask >> j & 1) { continue; }
        int nmask = mask | (1 << i) | (1 << j);
        dp[nmask] = max(dp[nmask], dp[mask] + F[i][j]);
      }
      break;
    }
  }
  int res = dp[(1<<n)-1];
  printf("%d\n", res);
  return 0;
}
0