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上收集的好玩,容易上手的开源项目. 目的:因为兴趣是最好的老师,我希望月刊中的内容可以激发读者 ...
随机推荐
- Android:日常学习笔记(9)———探究广播机制
Android:日常学习笔记(9)———探究广播机制 引入广播机制 Andorid广播机制 广播是任何应用均可接收的消息.系统将针对系统事件(例如:系统启动或设备开始充电时)传递各种广播.通过将 In ...
- 序列化+protobuff+redis
背景: 当redis里面需要存储 “key-字符串,value-对象” 时,是不能直接存对象,而是需要将序列化后的对象存进redis. redis没有实现内部序列化对象的功能,所以需要自己提前序列化对 ...
- OC源文件扩展名
常见的文件扩展名 扩展名 含义 扩展名 含义 .c C语言源文件 .mm Objective-C++源文件 .cc..cpp C++源文件 .pl Perl源文件 .h 头文件 .o Object(编 ...
- MyBatis传入多个参数 ,List集合
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- React-Native Listview组件用法详解
ListView作为React Native的核心组件,用于高效地显示一个可以垂直滚动的变化的数据列表.其中最重要的属性之一是DataSource,列表依赖的数据源,用于实例化一个ListView对象 ...
- 关于读取本地text文件,自动被添加空格的问题
最近做一个小程序,读取本地指定路径下的text文件,逐行获取text文本然后再进行处理,结果遇到了一个奇葩问题,先插个图片给各位看官 坑:本地text文件中数据为1123/10(数据反复检查无空格,换 ...
- Eclipse常用快捷键(转帖)
Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行(复制增加) Alt+ ...
- vs2010下创建webservice ----第一天(建立项目,以及不连数据库进行加减乘除)
Visual Studio 2010默认采用的框架为.NET Framework4,在这个框架中已找不到直接创建WebService的模板方式了.但VS2010可以创建WebService是毋庸置疑的 ...
- 微信小程序申请。很蛋疼的流程。
微信小程序申请. 营业执照,食品许可证,身份证正面,身份证反面. 1.先要申请服务号. 需要一个QQ邮箱,申请服务号. 填写各种信息,营业执照信息. 法人信息. 管理员用自己人的.方便开发操作. 申请 ...
- Hbase- Hbase客户端读写数据时的路由流程
1.客户端先到zookeeper查找hbase:meta所在的RegionServer服务器 2.去hbase:meta表查找自己所要的数据所在的region server 3.去目标region s ...