4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
NO YES
//************************************************************************// //*Author : Handsome How *// //************************************************************************// //#pragma comment(linker, "/STA CK:1024000000,1024000000") #pragma warning(disable:4996) #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <complex> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <cassert> using namespace std; typedef long long LL; char maze[10][10]; int vis[9][9]; int m, n, t; int dx[] = { -1,0,1,0 }; int dy[] = { 0,-1,0,1 }; int doorx, doory; bool check(int x, int y) { return (x >= 0 && x < m&&y >= 0 && y < n); } bool dfs(int x, int y,int now) { if (x == doorx&&y == doory&&now == t) return true; for (int i = 0; i < 4; i++) { if (check(x + dx[i], y + dy[i])) if(vis[x + dx[i]][y + dy[i]]==0) { vis[x + dx[i]][y + dy[i]] = 1; if (dfs(x + dx[i], y + dy[i], now + 1)) return true; vis[x + dx[i]][y + dy[i]] = 0; } } return false; } int main() { while (scanf("%d%d%d", &m,&n,&t) != EOF) { if (m == 0 && n == 0 && t == 0)break; getchar(); memset(vis, 0, sizeof(vis)); doorx = -1; int sx = -1, sy = -1; for (int i = 0; i < m; i++) { scanf("%s", maze[i]); getchar(); } if (t >= m*n) { printf("NO\n"); continue; } for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) { if (maze[i][j] == 'S') { sx = i, sy = j; vis[sx][sy] = 1;} if (maze[i][j] == 'D') { doorx = i, doory = j; } if (maze[i][j] == 'X') { vis[i][j] = 1; } } if ((abs(sx - doorx) + abs(sy - doory) - t) & 1) printf("NO\n"); else if (dfs(sx, sy,0))printf("YES\n"); else printf("NO\n"); } return 0; }