結果

問題 No.943 取り調べ
ユーザー imoni_kawaii
提出日時 2020-06-16 21:53:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 1,206 ms
コード長 1,211 bytes
コンパイル時間 2,789 ms
コンパイル使用メモリ 196,492 KB
最終ジャッジ日時 2025-01-11 04:44:13
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int dp[1<<20];

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> x(n, vector<int>(n));
  rep(i, n) rep(j, n) cin >> x[i][j];
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> mask(n);
  rep(i, n) {
    int t = 0;
    rep(j, n) {
      if(x[i][j]) t |= 1<<j;
    }
    mask[i] = t;
  }
  rep(S, 1<<20) dp[S] = INF;
  dp[0] = 0;
  rep(S, 1<<n) {
    if(dp[S] == INF) continue;
    rep(i, n) {
      if(S>>i&1) continue;
      int d = ((S&mask[i]) == mask[i] ? 0 : a[i]);
      chmin(dp[S|1<<i], dp[S]+d);
    }
  }
  cout << dp[(1<<n)-1] << '\n';
  return 0;
}
0