孤岛营救问题(BFS+状压DP)
孤岛营救问题
https://www.luogu.org/problemnew/show/P4011
用状压DP标记拿到钥匙的数量
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
using namespace std; int n,m,p;
int dir[][]={,,,,-,,,-};
int door[][][][];
int map[][];
int book[][][<<];
struct sair{
int x,y,step,key;
}; void bfs(){
sair s,e;
s.x=,s.y=,s.key=map[][],s.step=;
queue<sair>Q;
book[][][]=;
Q.push(s);
while(!Q.empty()){
s=Q.front();
Q.pop();
for(int i=;i<;i++){
e.x=s.x+dir[i][];
e.y=s.y+dir[i][];
if(e.x>=&&e.x<=n&&e.y>=&&e.y<=m&&(door[s.x][s.y][e.x][e.y]!=)){
if(e.x==n&&e.y==m){
cout<<s.step+<<endl;
return;
}
if((door[s.x][s.y][e.x][e.y]>)&&((s.key&door[s.x][s.y][e.x][e.y])>)){
int tmp=s.key;
if(!book[e.x][e.y][tmp]){
book[e.x][e.y][tmp]=;
e.step=s.step+;
e.key=s.key;
if(map[e.x][e.y]){
e.key|=map[e.x][e.y];
}
Q.push(e);
}
}
else if(door[s.x][s.y][e.x][e.y]==-){
int tmp=s.key;
if(!book[e.x][e.y][tmp]){
book[e.x][e.y][tmp]=;
e.step=s.step+;
e.key=s.key;
if(map[e.x][e.y]){
e.key|=map[e.x][e.y];
}
Q.push(e);
}
}
}
}
}
cout<<-<<endl;
return;
} int main(){
cin>>n>>m>>p;
int k;
cin>>k;
int x1,x2,y1,y2,G;
memset(door,-,sizeof(door));
for(int i=;i<=k;i++){
cin>>x1>>y1>>x2>>y2>>G;
if(!G){
door[x1][y1][x2][y2]=;
door[x2][y2][x1][y1]=;
}
else{
door[x1][y1][x2][y2]=(<<G);
door[x2][y2][x1][y1]=(<<G);
}
}
cin>>k;
for(int i=;i<=k;i++){
cin>>x1>>y1>>G;
map[x1][y1]|=(<<G);
}
bfs();
}
孤岛营救问题(BFS+状压DP)的更多相关文章
- 孤岛营救问题 (BFS+状压)
https://loj.ac/problem/6121 BFS + 状压 写过就好想,注意细节debug #include <bits/stdc++.h> #define read rea ...
- hdu 4856 Tunnels (bfs + 状压dp)
题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...
- HDU-4856 Tunnels (BFS+状压DP)
Problem Description Bob is travelling in Xi’an. He finds many secret tunnels beneath the city. In hi ...
- QDUOJ 来自xjy的签到题(bfs+状压dp)
来自xjy的签到题 Description 爱丽丝冒险来到了红皇后一个n*n大小的花园,每个格子由'.'或'#'表示,'.'表示爱丽丝可以到达这个格子,‘#’表示爱丽丝不能到达这个格子,爱丽丝每1 ...
- HDU-3681-Prison Break(BFS+状压DP+二分)
Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...
- #12【BZOJ3003】LED BFS+状压DP
题解: 看到区间修改先想一下差分 这题用差分是为了分析问题 现在的问题就变成了 原序列全为0,要使得特定的k个点变为1,每个操作改变x,y+1 然后我们会发现 对于二元组a,b我们要修改它,实际上是在 ...
- 洛谷P4011 孤岛营救问题(状压+BFS)
传送门 和网络流有半毛钱关系么…… 可以发现$n,m,p$都特别小,那么考虑状压,每一个状态表示位置以及钥匙的拥有情况,然后每次因为只能走一步,所以可以用bfs求出最优解 然后是某大佬说的注意点:每个 ...
- 【BZOJ 3049】【USACO2013 Jan】Island Travels BFS+状压DP
这是今天下午的互测题,只得了60多分 分析一下错因: $dis[i][j]$只记录了相邻的两个岛屿之间的距离,我一开始以为可以,后来$charge$提醒我有可能会出现来回走的情况,而状压转移就一次,无 ...
- CodeForces 907E Party(bfs+状压DP)
Arseny likes to organize parties and invite people to it. However, not only friends come to his part ...
随机推荐
- [转]IDEA 新建 JSP 项目时
本文转自:https://www.vastyun.com/bloger/670.html 新建的 jsp 页面不像 eclipse 的页面一样有 <% String path = request ...
- WDA编译失败问题
1.放假回来,wda编译失败,报错如下 2018-09-25 10:03:09.020964+0800 WebDriverAgentRunner-Runner[335:33309] +[CATrans ...
- 1084 Broken Keyboard (20 分)
1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...
- Effect
/////////////////////////////////shader source/////////////////////////////////Texture2D colorMap : ...
- AWR实战分析之---- PX Deq Credit: send blkd (转载)
该等待事件我在前面分析过,但是这次和上次产生的原因有些不一样,上次该等待事件的详细分析链接是:http://blog.sina.com.cn/s/blog_61cd89f60102eeen.html ...
- Erasure Coding(纠删码)深入分析
http://blog.sina.com.cn/s/blog_57f61b490102viq9.html 1.前言 Swift升级到2.0大版本后宣称开始支持纠删码,这其实是一个很有意义的特性,主要是 ...
- uva-10112-计算几何
题意:给你一些点,求这些点组成的三角形面积最大,而且三角形内不能包含其他点 #include <iostream> #include <math.h> #include< ...
- sbt的安装测试
1.下载 wget https://github.com/sbt/sbt/releases/download/v0.13.15/sbt-0.13.15.tgz 2.安装 tar -zxvf sbt-0 ...
- 微信小程序注册身份证验证
// 校验身份证号 //校验码校验 checkCode: function (val) { var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2])) ...
- PHP判断客户端是PCweb端还是移动手机端方法
/** * * 根据php的$_SERVER['HTTP_USER_AGENT'] 中各种浏览器访问时所包含各个浏览器特定的字符串来判断是属于PC还是移动端 * @author discuz3x * ...