結果
問題 |
No.3158 Collect Stamps
|
ユーザー |
![]() |
提出日時 | 2025-05-23 19:22:34 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 879 bytes |
コンパイル時間 | 3,286 ms |
コンパイル使用メモリ | 284,392 KB |
実行使用メモリ | 13,952 KB |
最終ジャッジ日時 | 2025-05-23 19:22:40 |
合計ジャッジ時間 | 5,773 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e18; int main() { int N, M, K; cin >> N >> M >> K; vector<bool> able(N, false); while(K--) { int t; cin >> t; able[--t] = true; } ll T[N][N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) cin >> T[i][j]; } vector dp(1<<N, vector<ll>(N, INF)); for (int i = 0; i < N; i++) { dp[1<<i][i] = 0; } for (int S = 0; S < (1<<N); S++) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { if (dp[S][i] == INF) continue; if (S>>j&1) continue; dp[1<<j|S][j] = min(dp[1<<j|S][j], dp[S][i] + T[i][j]); } } ll ans = INF; for (int S = 0; S < (1<<N); S++) for (int i = 0; i < N; i++) { if (popcount((unsigned)S) >= M) { for (int j = 0; j < N; j++) { if (able[j]) { ans = min(ans, dp[S][i] + T[i][j]); } } } } cout << ans << endl; }