結果
問題 |
No.3158 Collect Stamps
|
ユーザー |
![]() |
提出日時 | 2025-05-24 11:57:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,524 bytes |
コンパイル時間 | 3,664 ms |
コンパイル使用メモリ | 280,716 KB |
実行使用メモリ | 9,856 KB |
最終ジャッジ日時 | 2025-05-24 11:57:56 |
合計ジャッジ時間 | 4,780 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 WA * 8 |
ソースコード
#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include<bits/stdc++.h> using namespace std; using ll = long long; //https://boostjp.github.io/tips/multiprec-int.html #define YES cout<<"Yes"<<endl #define NO cout<<"No"<<endl #define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}// if(a==b)YN; #define NO2 cout<<-1<<endl #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i=int(n)-1; i>=0; --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() int pc(int n) { int cnt = 0; while (n>0) { cnt += n%2; n/=2; } return cnt; } int main() { int N, M, K; cin >> N >> M >> K; vector<int> A(N); rep(i, K) { cin >> A[i]; A[i]--; } vector<vector<int>> T(N, vector<int>(N)); rep(i,N)rep(j,N) cin >> T[i][j]; //dp[i][j] = {visited, last} vector<vector<int>> dp(1<<N, vector<int>(N, int(1e9))); rep(i, N) { dp[1<<i][i] = 0; } rep(i, (1<<N)) { rep(j, N) { if (((1<<j) & i) == 0) continue; rep(k, N) { if (i+(1<<k) >= (1<<N)) continue; //cerr << "now: " << i << " last: " << j << " next: " << k << ' ' << i+(1<<k) << endl; dp[i+(1<<k)][k] = min(dp[i+(1<<k)][k], dp[i][j] + T[j][k]); } } } int ans = int(1e9); rep(i, (1<<N)) { if (pc(i) < M) continue; for (int a:A) { ans = min(ans, dp[i][a]); } } cout << ans << endl; }