#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FF(i, a, b) for(int i=a; i=b; i--) #define REP(i, n) for(int i=0; i不可走 //vis[sta][i][j] = 1 :当前剩余sta中的黑子时,点已走过 bool can[SET][maxn][maxn], vis[SET][maxn][maxn]; char g[maxn][maxn]; //id[x][y] : 点的黑子对应的标号 int n, m, sx, sy, tot, id[maxn][maxn]; inline bool outside(int x, int y) { return x<0 || x>=n || y<0 || y>=m; } //当前剩余sta中的黑子 点x y是否在sta中 inline bool has(int sta, int x, int y) { return isalpha(g[x][y]) && (sta & (1< q; q.push(Node(sx, sy, tot, 0)); vis[tot][sx][sy] = 1; while(!q.empty()) { Node T = q.front(); q.pop(); if(T.st == 0) { printf("%d\n", T.steps); return ; } REP(i, 8) { int tx = T.x + dwx[i], ty = T.y + dwy[i]; if(outside(tx, ty)) continue; //如果当前状态 包含点的黑子 if(has(T.st, tx, ty)) { int sta = T.st&(tot-(1< = n || has(s, tx, ty)) break; can[s][tx][ty] = 1; } tx = i, ty = j; while(true) { tx--; if(tx < 0 || has(s, tx, ty)) break; can[s][tx][ty] = 1; } tx = i, ty = j; while(true) { ty++; if(ty>=m || has(s, tx, ty)) break; can[s][tx][ty] = 1; } tx = i, ty = j; while(true) { ty--; if(ty<0 || has(s, tx, ty)) break; can[s][tx][ty] = 1; } } } } } int main() { scanf("%d%d", &n, &m); tot = 0; REP(i, n) { scanf("%s", g[i]); REP(j, m) { if(g[i][j] == '*') sx = i, sy = j; else if(isalpha(g[i][j])) id[i][j] = tot++; } } if(tot == 0) { puts("0"); return 0; } tot = (1<