孤岛营救问题(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 ...
随机推荐
- PHP简单查询界面
<html> <style type='text/css'> table {border-collapse:collapse;} td {border:solid 1px #d ...
- appium 3-31626 toast识别
1.toast弹窗,普通方式不能获取 例如使用getPageSource是无法找到toast的信息,uiautomatorViewer加载页面时间较长,也很难采集到toast信息 2.通过curl命令 ...
- Class.forName和ClassLoader.loadClass的比较【转载】
Class的装载分了三个阶段,loading,linking和initializing,分别定义在The Java Language Specification的12.2,12.3和12.4.Clas ...
- python 网页抓取并保存图片
#-*-coding:utf-8-*- import os import uuid import urllib2 import cookielib '''获取文件后缀名''' def get_file ...
- GitLab更新远程分支信息
项目开发中,当远程分支有变动,有人增加或删除了某些分支,而自己本地没有及时自动刷新出来分支的时候,可以用以下命令来更新以下分支信息 git fetch origin --prune 恩,就酱-
- CentOS 6.6下安装配置Tomcat环境
本文转载至:http://www.linuxidc.com/Linux/2015-08/122234.htm 实验系统:CentOS 6.6_x86_64 实验前提:防火墙和selinux都关闭 实验 ...
- 安装MegaCli,查看linux服务器raid信息
1.下载安装包 下载地址:https://raw.githubusercontent.com/crazy-zhangcong/tools/master/MegaCli8.07.10.tar.gz 2. ...
- 大话java性能优化 pdf 下载(全本)
扫加公众号,回复”大话java性能优化",免费获取此书.
- uva-539-枚举
题意: 给你一个无向图,找最长路. 俩份代码,感觉map[][]简单易懂啊 #include<stdio.h> #include<iostream> #include<s ...
- pythone--002
元组就是不可修改: 字典的索引不是自增的. 元组和列表是: 默认 是key 通过get 没有这个key 是none get可以有默认值: 通过索引 没有就报错. 检查字典中某个可以是否存在:ha ...