abc079d <Floyed>
// https://atcoder.jp/contests/abc079/tasks/abc079_d
// <Floyed>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
using LL = long long;
int c[10][10];
void solv()
{
int h, w;
cin >> h >> w;
for (int i = 0; i <= 9; i ++)
for (int j = 0; j <= 9; j ++)
cin >> c[i][j];
for (int k = 0; k < 10; k ++)
for (int i = 0; i < 10; i ++)
for (int j = 0; j < 10; j ++)
c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
int ans = 0;
for (int i = 1; i <= h; i ++)
for (int j = 1; j <= w; j ++)
{
int t;
cin >> t;
if (t >= 0) ans += c[t][1];
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
{
solv();
}
return 0;
}
本文来自博客园,作者:O2iginal,转载请注明原文链接:https://www.cnblogs.com/o2iginal/p/17545075.html