用(x,s)表示一个状态,x表示机器人的位置,s表示其他位置有没有物体。用个fa数组和act数组记录和打印路径,转移的时候判断一下是不是机器人在动。
#includeusing namespace std;const int maxn = 16;const int maxe = 32;const int MAXSTA = 491520+10; // 2^15*15int head[maxn],to[maxe],nxt[maxe];int ecnt;void addEdge(int u,int v){ to[ecnt] = v; nxt[ecnt] = head[u]; head[u] = ecnt++;}struct Node{ int x,s; Node(){} Node(int X ,int S ){ x = X; s = S; }}q[MAXSTA];int fa[MAXSTA],dist[MAXSTA];struct Act{ int u,v; Act(int U = 0,int V = 0):u(U),v(V){}}act[MAXSTA];bool vis[32768][15];int n,m,s,t,sta;void print_ans(int u){ if(~fa[u])print_ans(fa[u]); else return; printf("%d %d\n",act[u].u+1,act[u].v+1);}void bfs(){ int _front = 0,rear = 0; q[rear].x = s; q[rear].s = sta; fa[rear] = -1; dist[rear++] = 0; memset(vis,0,sizeof(vis)); vis[sta][s] = true; while(_front >who&1){ int newSta = u.s^(1< >to[i]&1)^1) { Node &v = q[rear]; v.s = newSta|1<