​传送门​​ 思路:思路很清晰,简单。通过分析总共会有24种映射情况,所以分别枚举每一种情况,尝试即可。难得是模拟出来,想了好久。

#include<iostream>
#include<algorithm>
using namespace std;
char a[101][101];
string s;
int sx, sy;
int n, m;
void Map(int i)
{
if(i == 1)
sx ++;
if(i == 2)
sx --;
if(i == 3)
sy++;
if(i == 4)
sy--;
}
int main()
{
cin >> n >> m;
int xt,yt;
int cnt = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
if(a[i][j] == 'S')
sx = i, sy = j, xt = i, yt = j;
}
cin >> s;
for(int i = 1; i <= 4; i++)
for(int j = 1; j <= 4; j++)
for(int k = 1; k <= 4; k++)
for(int q = 1; q <= 4; q++)
{
if(i != j && i != k && i != q && j != k && j != q && k != q)
{
sx = xt, sy = yt;
for(int h = 0 ;h < s.size();h++)
{
if(s[h] == '0')
{
Map(i);
}
if(s[h] == '1')
{
Map(j);
}
if(s[h] == '2')
{
Map(k);
}
if(s[h] == '3')
{
Map(q);
}
if(sx <= 0 || sy <= 0 || sx > n || sy > m || a[sx][sy] == '#')
{break;}
if(a[sx][sy] == 'E')
{cnt++; break;}
}
}
}
cout << cnt << endl;
return 0;
}