之前这题超时的,因为每次都BFS了。
当时实在是蠢了,其实只要以终态为起点一次BFS就记录好所有路径了
#include <stdio.h>
#include <queue>
#include <iostream>
#include <string.h>
using namespace std;
#define N 1000000
struct node
{
int x,y;
char mat[3][3];
}p,pt;
char dir[N];
int nxt[N];
int move[][2] = {0,1,1,0,0,-1,-1,0};
char mo[5] = "lurd";
int fac[] = {1,1,2,6,24,120,720,5040,40320};
bool inner(int x,int y)
{
return x >=0 && x < 3 && y >=0 && y < 3;
}
int get_hash(node p)
{
int i,j,k,ans = 0,d;
char temp[10];
for(i = 0; i < 3; ++i)
for(j = 0; j < 3; ++j)
{
temp[i*3+j] =