1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 21; 4 int dp[1<<maxn][maxn]; 5 int maps[maxn][maxn]; 6 int main() { 7 int n; cin >> n; 8 for (int i = 0; i < n; i++) 9 for (int j = 0; j < n; j++) 10 cin >> maps[i][j]; 11 memset(dp,0x3f3f3f3f,sizeof(dp)); 12 dp[0][0] = 0; 13 for (int i = 0; i < (1<<n); i++) { 14 for (int j = 0; j < n; j++) { 15 if ((i>>j)&1) { 16 for (int k = 0; k < n; k++) { 17 if ((i>>k)&1) 18 dp[i][j] = min(dp[i][j],dp[i^(1<<j)][k]+maps[k][j]); 19 } 20 } 21 } 22 } 23 printf("%d\n",dp[(1<<n)-1][n-1]); 24 return 0; 25 }
原文地址:https://www.cnblogs.com/wstong/p/11764104.html
时间: 2024-10-09 22:09:47