1 条题解
-
0赵青海 (huhe) LV 7 SU @ 2021-8-8 1:32:49
C++ :
/***************************************** Problem Name : ******************************************/ #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 200 + 10; int a[N][N]; int p[1010]; int dp[1010][N][N]; int main() { int n,l; cin >> l >> n; for(int i = 1 ; i <= l ; i++) for(int j = 1 ; j <= l ;j++) cin >> a[i][j]; for(int i = 1 ; i <= n ; i++) cin >> p[i]; memset(dp,0x3f3f3f3f,sizeof(dp)); dp[0][1][2] = 0; p[0] = 3; for(int i = 0 ; i < n ; i++) for(int x = 1; x<= l ; x++) for(int y= 1; y<= l ; y++) { int z = p[i]; int v = dp[i][x][y]; if(z == x || x == y || z == y) continue; int u = p[i+1]; dp[i+1][x][y] = min(dp[i+1][x][y], v + a[z][u]); dp[i+1][z][y] = min(dp[i+1][z][y], v + a[x][u]); dp[i+1][x][z] = min(dp[i+1][x][z], v + a[y][u]); } int ans = 0x3f3f3f3f; int z = p[n]; for(int x = 1 ; x <= l ; x++) for(int y = 1 ; y <= l ; y++) { if(z == x || y == z || x == y) continue; ans = min(ans , dp[n][x][y]); } cout << ans << endl; }
- 1
信息
- ID
- 185
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 7
- 已通过
- 7
- 上传者