2800 take-out
time limit: 2 sspace limit: 256000 KBtitle level: Diamonds Diamond SolvingTitle Description
Description
There was a delivery, he had n orders on his hand, and he had to deliver n parts to the hands of n different clients. N different customers are in 1~n numbered cities. Delivery from the city of No. 0, and then N cities to walk once (a city can go many times), and finally back to 0 points (his unit), ask the shortest time is how much. The time for direct access to any two cities is now known.
Enter a description
Input Description
First line a positive integer n (1<=n<=15)
Next is a (n+1) * (n+1) matrix in which the number in the matrix is a positive integer that does not exceed 10000. The I row j column of the Matrix represents the time of the direct access between City I-1 and City j-1. Of course, the direct access time of city A to City B and City B to city A is not necessarily the same, that is, the road is one-way.
Output description
Output Description
A positive integer representing the minimum time spent
Sample input
Sample Input
30 1 10 101 0 1 210 1 0 1010 2 10 0
Sample output
Sample Output
8
Data range and Tips
Data Size & Hint
1<=n<=15
That is, state compression is difficult to think of points, data is very water.
1 //floyed+ pressure DP2#include <cstdio>3#include <cstring>4#include <iostream>5 using namespacestd;6 #defineN 217 intdis[n][n],f[n][1<< -];8 intMain () {9 intn,m;Tenscanf"%d",&n); One for(intI=0; i<=n;i++) A for(intj=0; j<=n;j++) -scanf"%d",&dis[i][j]); -Memset (F,127/3,sizeoff); thef[0][0]=0; - for(intk=0; k<=n;k++) - for(intI=0; i<=n;i++) - for(intj=0; j<=n;j++) + if(dis[i][j]>dis[i][k]+dis[k][j]&&i!=j&&i!=k&&j!=k) -dis[i][j]=dis[i][k]+Dis[k][j]; + intEnd= (1<< (n+1))-1; A for(intI=0; i<=end;i++) at for(intj=0; j<=n;j++) - for(intk=0; k<=n;k++){ - if((i| (1<<J))!=i)Continue; -F[j][i]=min (min (f[j][i],f[k][i-(1<<J)]+dis[k][j]), f[k][i]+Dis[k][j]); - } -printf"%d\n", f[0][end]); in return 0; -}
2800 Take-out