結果
| 問題 |
No.3158 Collect Stamps
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2025-05-24 06:41:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| コード長 | 1,113 bytes |
| コンパイル時間 | 3,111 ms |
| コンパイル使用メモリ | 277,792 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-05-24 06:41:48 |
| 合計ジャッジ時間 | 5,196 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
int dp[1<<16][16];
int T[16][16];
const int INF=1e9;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
rep(i,1<<16) rep(j,16) dp[i][j]=INF;
int n,m,k;
cin>>n>>m>>k;
V<int> A(n);
rep(i,k){
int a;
cin>>a;
a--;
A[a]=1;
}
rep(i,n) rep(j,n) cin>>T[i][j];
rep(i,n) dp[1<<i][i]=0;
for(int bit=1;bit<(1<<n);bit++){
rep(i,n){
if(dp[bit][i]==INF) continue;
rep(j,n){
if((bit>>j)&1) continue;
dp[bit|(1<<j)][j]=min(dp[bit|(1<<j)][j],dp[bit][i]+T[i][j]);
}
}
}
int ans=INF;
for(int bit=1;bit<(1<<n);bit++){
if(__builtin_popcount(bit)<m) continue;
rep(i,n){
if(A[i]) ans=min(ans,dp[bit][i]);
else{
int mi=INF;
rep(j,n){
if(A[j]) mi=min(mi,T[i][j]);
}
ans=min(ans,dp[bit][i]+mi);
}
}
}
cout<<ans<<endl;
return 0;
}
umezo