版本比较
启发式迭代加深搜索(IDA*)学习笔记
正文
增加 9 行删除 9 行
12 行未改动13141516171817181920212211 行未改动343536373838394041424343444546474849495051525354555354555657575859606136 行未改动12 行未改动using namespace std;#define rx registerconst int maxn=10;const int dx[maxn]={0,1,1,-1,-1,2,2,-2,-2};const int dy[maxn]={0,2,-2,2,-2,1,-1,1,-1};//步数 const int mason[maxn][maxn]={//2是空格,0白,1黑 const int dy[maxn]={0,2,-2,2,-2,1,-1,1,-1};//步数const int mason[maxn][maxn]={//2是空格,0白,1黑 {0,0,0,0,0,0}, {0,1,1,1,1,1}, {0,0,1,1,1,1}, {0,0,0,2,1,1},11 行未改动 if(now[i][j]!=mason[i][j])tot++; } } return tot;} }void IDA_star(int step,int x,int y,int mdep)//mdep最大深度{ if(step==mdep) { if(!f())flag=1;//全部归位 if(!f())flag=1;//全部归位 return; } for(int i=1;i<=8;i++) { int nx=x+dx[i],ny=y+dy[i]; if(nx<1 || nx>5 || ny<1 || ny>5)continue;//手欠打错了调了30minQwQ if(nx<1 || nx>5 || ny<1 || ny>5)continue;//手欠打错了调了30minQwQ swap(now[x][y],now[nx][ny]); if(step+f()<=mdep) { IDA_star(step+1,nx,ny,mdep); } swap(now[x][y],now[nx][ny]);//回溯 IDA_star(step+1,nx,ny,mdep); } swap(now[x][y],now[nx][ny]);//回溯 }} }char ch;signed main(){ scanf("%d",&t);36 行未改动