poj 2046 Gap(dfs&hash&壮压)(二)

2014-11-24 07:47:11 · 作者: · 浏览: 1
=0;i<4;i++) for(j=0;j<8;j++) tp+=st[i][j]*base[i*8+j];//都这么压。表示怀疑。 return tp; } ll bfs() { int x,y,i,j,k; yb tt; while(!q.empty()) q.pop(); q.push(tmp); while(!q.empty()) { tt=q.front(); if(tt.cod==over) return tt.step; for(k=0;k<4;k++) { tmp=tt; x=tmp.bx[k]; y=tmp.by[k]; if(tmp.maze[x][y-1]==0) continue; for(i=0;i<4;i++) { for(j=0;j<8;j++) { if(tmp.maze[i][j]!=tmp.maze[x][y-1]+1)//连续空格 continue; tmp.maze[x][y]=tmp.maze[i][j]; tmp.maze[i][j]=0; tmp.bx[k]=i; tmp.by[k]=j; if(!hm.Insert(tmp.cod=getcode(tmp.maze))) { tmp.step++; q.push(tmp); } } } } q.pop(); } return -1; } int main() { int i,j,k,n,tt,cnt; base[0]=1; for(i=1;i<=33;i++) base[i]=base[i-1]<<1; while(~scanf("%d",&n)) { for(k=0;k