|
- #include <algorithm>
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <map>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- long long n,d[200][200],t,book[20],a[20],ans=0x3f3f3f3f;
- void dfs(long long dis,long long last)
- {
- int e=0;
- for(int i=1;i<=t;i++)
- if(!book[i])
- {
- e=1;
- book[i]=1;
- dfs(dis+d[last][a[i]],a[i]);
- book[i]=0;
- }
- if(!e)
- ans=min(ans,dis+d[last][n]);
- }
- int main()
- {
- scanf("%lld",&n);
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- scanf("%lld",&d[i][j]);
- for(int k=1;k<=n;k++)
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
- scanf("%lld",&t);
- for(int i=1;i<=t;i++)
- {
- scanf("%lld",&a[i]);
- if(a[i]==1)
- book[i]=1;
- }
- dfs(0,1);
- printf("%lld",ans);
- return 0;
- }
复制代码 |
|