孤岛营救问题(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 ...
随机推荐
- 学习笔记之Visual Studio Team Services
VSTS and TFS Documentation | Microsoft Docs https://docs.microsoft.com/en-us/vsts/index?view=vsts#pi ...
- Find substring with K distinct characters
Given a string and number K, find the substrings of size K with K distinct characters. If no, output ...
- appium 3-31626 toast识别
1.toast弹窗,普通方式不能获取 例如使用getPageSource是无法找到toast的信息,uiautomatorViewer加载页面时间较长,也很难采集到toast信息 2.通过curl命令 ...
- shell 11函数
函数定义 function 方法名(){ command return int; } 注意:function可加可不加 #shell #!/bin/sh function fun1(){ echo & ...
- 针对ROS5版本的配置导出和导入(迁移其他服务器)
1.在老ROS,导出当前系统配置export compact RouterOS 5.12 新增功能 export compact 命令,该命令简化了导出的参数,仅导出修改的配置,系统默 认配置参数将不 ...
- Xss漏洞原理分析及简单的讲解
感觉百度百科 针对XSS的讲解,挺不错的,转载一下~ XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XS ...
- ZooKeeper系列(1) 整体介绍(转)
原文地址:https://www.cnblogs.com/wuxl360/p/5817471.html 一.分布式协调技术 在给大家介绍ZooKeeper之前先来给大家介绍一种技术——分布式协调技术. ...
- Supervisor: 进程控制系统
Supervisor: 进程控制系统 概述:Supervisor是一个 Client/Server模式的系统,允许用户在类unix操作系统上监视和控制多个进程,或者可以说是多个程序. 它与launch ...
- 0_Simple__vectorAdd + 0_Simple__vectorAdd_nvrtc + 0_Simple__vectorAddDrv
▶ 使用 CUDA Runtime API,运行时编译,Driver API 三种接口计算向量加法 ▶ 源代码,CUDA Runtime API #include <stdio.h> #i ...
- linux教程
linux视频教程:尚观 http://www.uplinux.com/shipin/linuxyong-hu-guan-li-zhi-yong-hu-guan-li-01 一,linux开机(cen ...