Garlic King get a treasure map. The treasure Map is a square map of 10x1010 \times 1010x10, a total of 101,010 treasures on the map. Some square terrain is too dangerous to enter.
There is only one place to access the whole map, that is, the entrance is also the exit. Garlic is a greedy man, he planned to obtain all the treasures before leaving from the exit.
The treasure map from a square to adjacent to the next left and right squares need 111 days, garlic June from the entrance, find all the treasure, back to the exit, the minimum number of days required.
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <
algorithm> typedef long Long LL;
using namespace Std;
const int MAXN=20;
const int inf=0x3f3f3f3f;
struct pos{int x, y;
POS () {} pos (int _x,int _y) {x=_x,y=_y;
}}POS[MAXN]; /* Input data 15-minute character simpler preprocessing of any two-point path, mainly a path selection, enumeration of all cases, so a series of sequences to represent */int mp[10][10]={{0,0,0,0,0,0,0,1,0,0}, {0,0,0,-1,0, 0,2,0,0,0}, {0,-1,0,0,3,0,0,-1,0,0}, {0,4,0,0,0,-1,0,0,5,0}, {0,-1,0,0,6,0,-1,0,0,0}, {0,0,-1,0,0,0,0,-1,0,0}, {
0,0,0,0,0,-1,0,0,7,0}, {0,-1,0,-1,0,0,8,0,0,0}, {0,9,0,0,0,0,-1,-1,0,0}, {0,0,-1,0,0,-1,10,0,0,0}};
struct node{int x, y;
int sum;
}NOW,NXT;
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int VIS[MAXN][MAXN];
int Get_dis (int st,int ed) {memset (vis,0,sizeof (VIS));
Queue<node> Q;
NOW.X=POS[ST].X,NOW.Y=POS[ST].Y;
Vis[now.x][now.y]=1;
now.sum=0;
Q.push (now);
while (!q.empty ()) {Now=q.front ();
if (NOW.X==POS[ED].X&&NOW.Y==POS[ED].Y) {return now.sum; } q.pop ();
for (int i=0;i<4;i++) {int nx=now.x+dir[i][0],ny=now.y+dir[i][1];
if (!vis[nx][ny]&&mp[nx][ny]!=-1) {vis[nx][ny]=1;
nxt.x=nx,nxt.y=ny,nxt.sum=now.sum+1;
Q.push (NXT);
}}} return INF;
} int DIS[MAXN][MAXN];
int rk[10];
int check () {int ans=0;
Ans+=dis[0][rk[0]];
for (int i=1;i<10;i++) {ans+=dis[rk[i]][rk[i-1]];
} Ans+=dis[rk[9]][0];
return ans;
} void Init () {for (int. i=0;i<=10;i++) {for (int j=i+1;j<=10;j++) {Dis[i][j]=dis[j][i]=get_dis (i,j);
}}} int main () {pos[0]= (pos) {0,0};
Pos[1]= (Pos) {0,7};
Pos[2]= (Pos) {1,6};
Pos[3]= (Pos) {2,4};
Pos[4]= (Pos) {3,1};
Pos[5]= (Pos) {3,8};
Pos[6]= (Pos) {bis};
Pos[7]= (Pos) {6,8};
Pos[8]= (Pos) {7,6};
Pos[9]= (Pos) {8,1};
Pos[10]= (Pos) {9,6};
for (int i=0;i<10;i++) {rk[i]=i+1;
} init ();
int ans=inf;
do{ans=min (Ans,check ());
printf ("***ans:%d\n", ans);
}while (Next_permutation (rk,rk+10));
printf ("%d\n", ans);
return 0;
}