結果
問題 | No.943 取り調べ |
ユーザー |
|
提出日時 | 2019-12-06 12:58:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 186 ms / 1,206 ms |
コード長 | 1,008 bytes |
コンパイル時間 | 1,755 ms |
コンパイル使用メモリ | 173,004 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 05:09:56 |
合計ジャッジ時間 | 3,753 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector< vector<int> > x(n, vector<int>(n)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> x[i][j]; } } vector<ll> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<ll> dp(1 << n, 1e15); dp[0] = 0; for (int i = 0; i < (1 << n) - 1; i++) { for (int j = 0; j < n; ++j) { if (i & (1 << j)) continue; int next_mask = (i | (1 << j)); ll cost = 0; for (int k = 0; k < n; ++k) { if (i & (1 << k)) continue; if (x[j][k]) { cost += a[k]; next_mask |= (1 << k); } } dp[next_mask] = min(dp[next_mask], dp[i] + cost); } } cout << dp[(1 << n) - 1] << "\n"; return 0; }