結果
| 問題 | No.3158 Collect Stamps | 
| コンテスト | |
| ユーザー |  沙耶花 | 
| 提出日時 | 2025-05-23 19:53:07 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 48 ms / 2,000 ms | 
| コード長 | 812 bytes | 
| コンパイル時間 | 4,353 ms | 
| コンパイル使用メモリ | 253,380 KB | 
| 実行使用メモリ | 9,856 KB | 
| 最終ジャッジ日時 | 2025-05-23 19:53:38 | 
| 合計ジャッジ時間 | 5,797 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 35 | 
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 4000000000000000001LL
int main(){
	
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> a(k);
	rep(i,k){
		cin>>a[i];
		a[i]--;
	}
	vector t(n,vector<int>(n));
	rep(i,n){
		rep(j,n)cin>>t[i][j];
	}
	vector dp(1<<n,vector<int>(n,Inf32));
	rep(i,n){
		dp[1<<i][i] = 0;
	}
	rep(i,1<<n){
		rep(j,n){
			if(dp[i][j] == Inf32)continue;
			rep(l,n){
				if((i>>l)&1)continue;
				dp[i|(1<<l)][l] = min(dp[i|(1<<l)][l],dp[i][j]+t[j][l]);
			}
		}
	}
	int ans = Inf32;
	rep(i,k){
		rep(j,1<<n){
			if(__builtin_popcount(j)<m)continue;
			ans = min(ans,dp[j][a[i]]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
            
            
            
        