結果
問題 | No.943 取り調べ |
ユーザー | iqueue02 |
提出日時 | 2019-12-06 12:06:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 165 ms / 1,206 ms |
コード長 | 894 bytes |
コンパイル時間 | 1,680 ms |
コンパイル使用メモリ | 171,608 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 05:07:01 |
合計ジャッジ時間 | 3,452 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int,int> P; constexpr int INF = 1e9; int main(){ 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> ok(n,0); rep(i,n) rep(j,n) if (x[i][j] == 1) ok[i] |= (1 << j); vector<int> dp(1<<n, INF); dp[0] = 0; for (int bit = 0; bit < (1 << n); bit++) { for (int j = 0; j < n; j++) { if (bit & (1 << j)) continue; int key = 0; for (int k = 0; k < n; k++) if (bit & (1 << k) && x[j][k]) key |= (1 << k); if (key == ok[j]) dp[bit | (1 << j)] = min(dp[bit | (1 << j)], dp[bit]); else dp[bit | (1 << j)] = min(dp[bit | (1 << j)], dp[bit] + a[j]); } } cout << dp[(1<<n)-1] << endl; return 0; }