拯救大兵瑞恩 HDU - 4845(状压bfs || 分层最短路)
1、状压bfs
这个状压体现在key上 我i们用把key状压一下 就能记录到一个点时 已经拥有的key的种类
ban[x1][y1][x2][y1]记录两个点之间的状态 是门 还是墙 还是啥都没有
inc[x][y]记录这个点所存储的钥匙 (可能不止一个 所以要用二进制)
vis[x][y][key] 标记当前点 在拥有的钥匙种类为key时是否走过
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m, p, k, s;
int ban[maxn][maxn][maxn][maxn], inc[maxn][maxn];
int vis[maxn][maxn][ << + ];
int dis[][] = {{, }, {-, }, {, }, {, -}}; struct node
{
int x, y, key, d;
node(int x, int y, int key, int d) : x(x), y(y), key(key), d(d) {}
}; int bfs()
{
queue<node> Q;
mem(vis, );
Q.push(node(, , | inc[][], ));
vis[][][ | inc[][]] = ;
while(!Q.empty())
{
node is = Q.front(); Q.pop();
for(int i = ; i < ; i++)
{
node it(, , , );
it.x = is.x + dis[i][];
it.y = is.y + dis[i][];
if(it.x < || it.x > n || it.y < || it.y > m)
continue;
if(!ban[it.x][it.y][is.x][is.y])
continue;
if(ban[it.x][it.y][is.x][is.y] == - || is.key & ( << (ban[it.x][it.y][is.x][is.y] -))) //如果下一个点与当前点没有墙或门 或者到当前点时已经有了进入下一个点的钥匙
{
if(!inc[it.x][it.y]) it.key = is.key; //如果下一个点没有存储的钥匙 则直接把当前钥匙传递过去
else it.key = is.key | inc[it.x][it.y]; //如果有存储的钥匙 把存储的钥匙加上即可
if(!vis[it.x][it.y][it.key])
{
vis[it.x][it.y][it.key] = ;
it.d = is.d + ;
Q.push(it);
if(it.x == n && it.y == m)
return it.d;
}
}
}
}
return -;
} int main()
{
while(cin >> n >> m >> p >> k)
{
int x1, y1, x2, y2, G, Q;
mem(ban, -);
mem(inc, );
for(int i = ; i <= k; i++)
{
cin >> x1 >> y1 >> x2 >> y2 >> G;
ban[x1][y1][x2][y2] = ban[x2][y2][x1][y1] = G;
}
cin >> s;
for(int i = ; i <= s; i++)
{
cin >> x1 >> y1 >> Q;
inc[x1][y1] |= ( << (Q - ));
}
cout << bfs() << endl; } return ;
}
2、 分层最短路
最短路是好写,但这个建图比较麻烦吧。。
可能说的是一个把。。。emm。。。
参考论文
拯救大兵瑞恩 HDU - 4845(状压bfs || 分层最短路)的更多相关文章
- hdu 4845 状压bfs(分层思想)
拯救大兵瑞恩 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Subm ...
- hdu 5094 状压bfs+深坑
http://acm.hdu.edu.cn/showproblem.php?pid=5094 给出n*m矩阵 给出k个障碍,两坐标之间存在墙或门,门最多10种,状压可搞 给出s个钥匙位置及编号,相应的 ...
- HDU 4012 Paint on a Wall(状压+bfs)
Paint on a Wall Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- HDU Stealing Harry Potter's Precious(状压BFS)
状压BFS 注意在用二维字符数组时,要把空格.换行处理好. #include<stdio.h> #include<algorithm> #include<string.h ...
- POJ 1324 Holedox Moving (状压BFS)
POJ 1324 Holedox Moving (状压BFS) Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18091 Acc ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- P2622 关灯问题II(状压bfs)
P2622 关灯问题II 题目描述 现有n盏灯,以及m个按钮.每个按钮可以同时控制这n盏灯——按下了第i个按钮,对于所有的灯都有一个效果.按下i按钮对于第j盏灯,是下面3中效果之一:如果a[i][j] ...
- 状压BFS
题意:1个机器人找几个垃圾,求出最短路径. 状压BFS,这道题不能用普通BFS二维vis标记数组去标记走过的路径,因为这题是可以往回走的,而且你也不能只记录垃圾的数量就可以了,因为它有可能重复走同一 ...
- HDU 4845 拯救大兵瑞恩(分层图状压BFS)
拯救大兵瑞恩 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Sub ...
随机推荐
- 常用gcc选项
<Linux GCC常用命令> Makefile有三个非常有用的变量.分别是$@,$^,$<代表的意义分别是: $@--目标文件,$^--所有的依赖文件,$<--第一个依赖文件 ...
- 虚拟机vbox
https://www.virtualbox.org/wiki/Linux_Downloads 一直在报内核出错的问题,我尝试了各种方法还是无果,猜测是版本的问题,这里推荐各位安装virtualbox ...
- linux shell的here document用法
转载自: http://my.oschina.net/u/1032146/blog/146941 什么是Here Document?Here Document 是在Linux Shell 中的一种特殊 ...
- 解决微软surface pro在某些情况下wifi转输速度过慢的问题 - z
我是新款i7 surface.昨天到的货,狗东. 在公司使用的时候网络很正常,但回到家里之后就特别卡.5G频段也特别卡,基本处于无法观看视频的地步.台式电脑(我台式用的无线网卡)和手机都没问题. 于是 ...
- vue 结合mint-ui Message box的使用方法
两种方式使用: 一.全局注册 1.在main.js中引入 //引入 import { MessageBox } from 'mint-ui'; //全局使用,挂载到原型上 Vue.prototyp ...
- VS2015 搭建 Asp.net core 开发环境
1.首先你得装个vs2015 并且保证已经升级至 update3及以上(此处附上一个vs2015带up3的下载链接: ed2k://|file|cn_visual_studio_enterprise_ ...
- Java 基础之一对象导论
对象导论 1.1 抽象过程 所有编程语言都提供抽象机制.人们所能解决的问题的复杂性直接取决于抽象的类型和质量. 汇编语言是对底层机器的轻微抽象. 我们将问题空间中的元素及其再解空间中的表示称为对象.这 ...
- Centos下安装破解Jira7的操作记录
Jira是一个集项目计划.任务分配.需求管理.错误跟踪于一体的工具,可以作为一个bug管理系统,可以将在测试过程中所发现的bug录入.分配给开发人员.前面介绍了Confluence在Centos下的安 ...
- Linux内核分析 读书笔记 (第十八章)
第十八章 调试 18.1 准备开始 1. 需要的只是: 一个bug 一个藏匿bug的内核版本 相关内核代码的知识和运气 2. 在跟踪bug的时候,掌握的信息越多越好. 18.2 内核中的bug 1. ...
- Github上传更新
通过2天的时间,不停的网上找各种资料,今天下午终于可以登录上github for Windows 客户端了,,, 然后通过一整晚的摸索,也把项目上传到github里. github地址:https:/ ...