//奇偶剪枝
//01010101
//10101010
//01010101
//10101010
//1奇数步走到0,1偶数步走到1.
#include<stdio.h>
#include<string.h>
#include<stack>
int n,m,t,ans = 0;
const int maxn = 1e3;
char a[maxn][maxn];
int vis[maxn][maxn];
int dx[10] = {0,0,-1,1,1,1,-1,-1};
int dy[10] = {1,-1,0,0,-1,1,-1,1};
void dfs(int xx,int yy,int k){
if (a[xx][yy] == 'D' && k == t){
ans = 1;
}
if (ans == 1) return;
if (k == t) return;
vis[xx][yy] = 1;
for (int i = 0; i < 4; i++){
int x = xx + dx[i];
int y = yy + dy[i];
if (x < 0 || y < 0 || x >= n || y >= m) continue;
if (vis[x][y]) continue;
if (a[x][y] == 'X') continue;
dfs(x,y,k+1);
}
vis[xx][yy] = 0;
}
int main (){
while (scanf("%d%d%d", &n, &m, &t) != EOF && n != 0){
for (int i = 0; i < n; i++){
scanf("%s",a[i]);
}
int sx, sy;
int ex, ey;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (a[i][j] == 'S'){
sx = i;
sy = j;
}
if (a[i][j] == 'D'){
ex = i;
ey = j;
}
}
}
if ((sx + sy) % 2 == (ex + ey) % 2 && t % 2 == 1){
printf("NO\n");
continue;
}
if ((sx + sy) % 2 != (ex + ey) % 2 && t % 2 == 0){
printf("NO\n");
continue;
}
memset(vis, 0, sizeof(vis));
vis[sx][sy] = 1;
ans = 0;
dfs(sx,sy,0);
if (ans == 0){
printf("NO\n");
}
if (ans == 1){
printf("YES\n");
}
}
}
HDU 1010 Tempter of the Bone
最新推荐文章于 2022-12-04 15:41:50 发布