New Year and Buggy Bot
Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.
The robot can only move up, left, right, or down.
When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.
The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.
Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.
Input
The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.
Output
Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.
Example
5 6
.....#
S....#
.#....
.#....
...E..
333300012
1
6 6
......
......
..SE..
......
......
......
01232123212302123021
14
5 3
...
.S.
###
.E.
...
3
0
Note
For the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.
只要安全到达出口就可以了,可以有多余的指令。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int n,m,dir[][] = {,,,,,-,-,},c = ,visited[],f[],sx,sy;
char mp[][],s[];
int check()
{
int px = sx,py = sy;
for(int i = ;s[i];i ++)
{
px += dir[f[s[i] - '']][],py += dir[f[s[i] - '']][];
if(px < || py < || px >= n || py >= m || mp[px][py] == '#')return ;
if(mp[px][py] == 'E')return ;
}
return ;
}
void dfs(int k)
{
if(k == )
{
if(check())c ++;
return;
}
for(int i = ;i < ;i ++)
{
if(!visited[i])
{
visited[i] = ;
f[k] = i;
dfs(k + );
visited[i] = ;
}
}
}
int main()
{
cin>>n>>m;
for(int i = ;i < n;i ++)
{
for(int j = ;j < m;j ++)
{
cin>>mp[i][j];
if(mp[i][j] == 'S')sx = i,sy = j;
}
}
cin>>s;
dfs();
cout<<c;
}
New Year and Buggy Bot的更多相关文章
- 【Good Bye 2017 B】 New Year and Buggy Bot
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举一下全排列.看看有多少种可以到达终点即可. [代码] #include <bits/stdc++.h> using ...
- Codeforces New Year and Buggy Bot 题解
主要思路:全排列,然后按输入的字符串走并且判断是否撞墙 注:这样不会TLE,全排列最多24种 Code(C++): #include<bits/stdc++.h> using namesp ...
- 冬训 day2
模拟枚举... A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B) 暴力枚举即可,但是直接手动暴力会非 ...
- Good Bye 2017
太菜了啊,一不小心就goodbye rating了 A. New Year and Counting Cards time limit per test 1 second memory limit p ...
- [Codeforces]Good Bye 2017
A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...
- Good Bye 2017 A B C
Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...
- CodeForces Goodbye 2017
传送门 A - New Year and Counting Cards •题意 有n张牌,正面有字母,反面有数字 其中元音字母$a,e,o,i,u$的另一面必须对应$0,2,4,6,8$的偶数 其他字 ...
- cf 908B
B - New Year and Buggy Bot 思路:刚开始看到这个题的时候,一头雾水,也不知道要干什么,后来百度翻译了了一遍,看明白了,不得不说自己的英语太差了,好了,步入正题: 给你n行m列 ...
- 《HelloGitHub》之GitHub Bot
起因 我在github上发起了一个开源项目:<HelloGitHub月刊>,内容是github上收集的好玩,容易上手的开源项目. 目的:因为兴趣是最好的老师,我希望月刊中的内容可以激发读者 ...
随机推荐
- python之路(sed,函数,三元运算)
python之路(sed,函数,三元运算) 一.sed集合 1.set无序,不重复序列 2.创建 se = {11,22,33,33,44} list() #只要是一个类加上()自动执行 list _ ...
- 吐槽 坑爹的MySQL安装路径选择
一般再windows下面安装MySQL我们都会选择msi安装模式,然而安装最新版的MySQL(mysql-installer-community-5.7.11.0.msi 下载地址)发现MySQL默认 ...
- 键盘没有Home键和End键的完美解决办法
最近新入手一个笔记本,发现键盘没有Home/End,这两个键虽然不是必用,但也是用顺手了,特别是选择一行,到行首,行尾的时候甚是方便 作为一枚程序员,怎么能够妥协? 于是开始研究 方案一 通过观察笔记 ...
- Linux Shell基础 多个命令中的分号(;)、与(&&) 、 或(||)
概述 在 Bash 中,如果需要让多条命令按顺序执行,则有这样方法,如表 1 所示. 多命令执行符 格 式 作 用 : 命令1 ; 命令2 多条命令顺序执行,命令之间没有任何逻辑关系 &&am ...
- Docker容器技术-自动化部署
一.用Chef自动化部署Docker 1.为什么需要自动化部署? Docker引擎需要配置很多参数(cgroups.内存.CPU.文件系统等) 识别Docker容器运行在哪个宿主机上 耗时且容易出错, ...
- INSPIRED启示录 读书笔记 - 第31章 苹果公司给我的启示
苹果公司值得学习的经验 1.硬件为软件服务:苹果公司明白硬件必须为软件服务,软件直接服务用户,满足用户需求.采用多点触控显示屏.重力加速器.距离传感器这些硬件技术是为了配合软件满足用户需求 2.软件为 ...
- Anaconda创建环境、删除环境、激活环境、退出环境
Anaconda创建环境: //下面是创建python=3.6版本的环境,取名叫py36 conda create -n py36 python=3.6 删除环境(不要乱删啊啊啊) conda re ...
- linux运维面试题1
一.填空题 1. 在Linux 系统 中,以文件方式访问设备 . 2. Linux 内核引导时,从文件/etc/fstab中读取要加载的文件系统 . 3. Linux 文件系统中每个文件用indoe节 ...
- Kubernetes TLS认证
转自: https://mritd.me/2018/01/07/kubernetes-tls-bootstrapping-note/ 前段时间撸了一会 Kubernetes 官方文档,在查看 TLS ...
- Spark常用算子-KeyValue数据类型的算子
package com.test; import java.util.ArrayList; import java.util.List; import java.util.Map; import or ...