博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
孤岛营救问题 (BFS+状压)
阅读量:7172 次
发布时间:2019-06-29

本文共 1705 字,大约阅读时间需要 5 分钟。

BFS + 状压

写过就好想,注意细节debug

#include 
#define read read()#define up(i,l,r) for(register int i = (l);i <= (r);i++)#define down(i,l,r) for(register int i = (l);i >= (r);i--)#define traversal_vedge(i) for(register int i = head[u]; i ;i = e[i].nxt)#define ll long longusing namespace std;int read{ int x = 0, f = 1; char ch = getchar(); while(ch < 48 || ch > 57) {
if(ch == '-')f = -1; ch = getchar();} while(ch >=48 && ch <=57) {x = 10 * x + ch - 48;ch = getchar();} return x * f; }void write(int x){ if(x < 0) x = -x,putchar('-'); if(x > 9) write(x/10); putchar(x%10 + 48);}//-----------------------------------------------------------------const int N = 12;int n,m,p,k,s;int maps[N][N][N][N],cnt[N][N],type[N][N][N],vis[N][N][(1<
q; int s = get_state(1,1); q.push((node){
1,1,0,s} ); vis[1][1][s] = 1; while(!q.empty()) { node u = q.front(); q.pop(); int x = u.x,y = u.y; if(x == n && y == m) return u.step; up(i,1,4) { int nx = x + dx[i],ny = y + dy[i]; if(nx < 1 || ny < 1 || nx > n || ny > m) continue; int obstacle = maps[x][y][nx][ny]; if(obstacle == -1) continue; if( obstacle > 0 && (u.state & 1<<(obstacle - 1)) == 0 ) continue;//debug obstacle - 1 <- 1 - obstacle int ns = u.state|get_state(nx,ny);//degug u.state <- s; if(vis[nx][ny][ns]) continue; vis[nx][ny][ns] = 1; q.push( (node){nx,ny,u.step+1,ns} ); } } return -1;}int main(){ freopen("input.txt","r",stdin); readdata(); printf("%d\n",bfs()); return 0;}

 

转载于:https://www.cnblogs.com/mzg1805/p/10410449.html

你可能感兴趣的文章
Cview的派生类
查看>>
Android activity的生命周期
查看>>
HTML5+Css3-webkit-filter
查看>>
css border-bottom(指定下边线的样式、宽度及颜色)
查看>>
P1352 没有上司的舞会
查看>>
Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
查看>>
关于《淘宝技术这十年》
查看>>
System类
查看>>
某网站html的注释
查看>>
macos mojave 安装brew 出错总结
查看>>
HDU 1667 Nested Dolls
查看>>
SQL数据库类型
查看>>
XGPush集成(信鸽集成)demo
查看>>
结构化异常处理 读书笔记
查看>>
性能优化3--数据库优化
查看>>
JavaScript知识点回顾
查看>>
关于浏览器兼容处理的几种方式
查看>>
第一个Asp.net小项目,主页写了下后台代码
查看>>
(推荐使用)SpringMVC注解,基本配置
查看>>
ORA-12547: TNS:lost contact+oracle 开启监听失败
查看>>