#include #include //小数点出力用 //cout << fixed << setprecision(10) << ans; #include #include #include #include #include #include #include #include using ll = long long; using namespace std; #define modP7 1'000'000'007 #define modP 998244353 bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); } int clk4(int num) { return (num - 2) * (num % 2); } void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); } bool include3(string S) { for (int i = 0;i < S.size();i++) { if (S[i] == 0x33) { return 1; } } return 0; } bool multi3(string S) { int res = 0; for (int i = 0;i < S.size();i++) { res += (int)(S[i] - 0x30); } if (res % 3 == 0) { return 1; } return 0; } int main() { int N, M, K; cin >> N >> M >> K; bool G[20] = { 0 }; for (int i = 0;i < K;i++) { int A; cin >> A; G[A] = 1; } int T[20][20]; for (int i = 1;i <= N;i++) { for (int j = 1;j <= N;j++) { cin >> T[i][j]; } } int route[6] = { 1,2,3,4,5,6 }; int best = 1e9; while (1) { do { int res = 0; for (int j = 1;j < M;j++) { res += T[route[j - 1]][route[j]]; } if (!G[route[M - 1]]) { res += T[route[M - 1]][route[M]]; } best = min(best, res); } while (next_permutation(route, route + M + 1)); { int i = M; while (route[i] == N - (M - i)) { i--; if (i == -1) { cout << best; return 0; } } route[i]++; i++; for (;i <= M;i++) { route[i] = route[i - 1] + 1; } } } return 0; }