题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’;判断能否从S正好走t步到D。

题解:dfs,奇偶性减枝,剩余步数剪枝。

ps:帮室友Debug的题:打错了两个字母。题目看错。没有初始化map。orz ...不过我dfs也不熟,更别说剪枝了。

//#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
#define LL long long
int n, m, T;
int si, sj, ei, ej;
char a[][];
int map[][];
int dir[][] = { { , },{ -, },{ , },{ ,- } };
int check(int i, int j, int t) {
if (i< || i >= n || j< || j >= m || map[i][j] || a[i][j] == 'X') return false; return true;
}
bool dfs(int i, int j, int t) { if (i == ei&&j == ej&&t==T) return true;
if (t>=T) return false;
map[i][j] = ;
for (int k = ; k<; k++) {
int di = i + dir[k][];
int dj = j + dir[k][];
if (!check(di, dj, t + )) continue;
if (dfs(di, dj, t + ))
return true;
map[di][dj] = ;
}
return false;
}
int main() {
while (~scanf("%d%d%d", &n, &m, &T)) {
if (n == && m == && T == ) break;
memset(map, , sizeof(map));
for (int i = ; i<n; i++)
scanf("%s", a[i]);
int ok = ;
for (int i = ; i<n; i++) {
for (int j = ; j<m; j++) {
if (a[i][j] == 'D') {
ei = i; ej = j;
ok++;
}
if (a[i][j] == 'S') {
si = i; sj = j;
ok++;
}
if (ok == ) break;
}
if (ok == ) break;
}
if ((T - (abs(ei - si) + abs(ej - sj))) % || (T - (abs(ei - si) + abs(ej - sj)))<) printf("NO\n");
else if (dfs(si, sj,)) printf("YES\n");
else printf("NO\n");
}
return ;
}

Hdu1010Tempter of the Bone 深搜+剪枝的更多相关文章

  1. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  2. HDU 1010 Temper of the bone(深搜+剪枝)

    Tempter of the Bone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) ...

  3. hdu1010 Tempter of the Bone(深搜+剪枝问题)

    Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...

  4. Hdu3812-Sea Sky(深搜+剪枝)

    Sea and Sky are the most favorite things of iSea, even when he was a small child.  Suzi once wrote: ...

  5. poj1190 生日蛋糕(深搜+剪枝)

    题目链接:poj1190 生日蛋糕 解题思路: 深搜,枚举:每一层可能的高度和半径 确定搜索范围:底层蛋糕的最大可能半径和最大可能高度 搜索顺序:从底层往上搭蛋糕,在同一层尝试时,半径和高度都是从大到 ...

  6. UVA 10160 Servicing Stations(深搜 + 剪枝)

    Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...

  7. ACM 海贼王之伟大航路(深搜剪枝)

    "我是要成为海贼王的男人!" 路飞他们伟大航路行程的起点是罗格镇,终点是拉夫德鲁(那里藏匿着"唯一的大秘宝"--ONE PIECE).而航程中间,则是各式各样的 ...

  8. hdu 1518 Square(深搜+剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1518 题目大意:根据题目所给的几条边,来判断是否能构成正方形,一个很好的深搜应用,注意剪枝,以防超时! ...

  9. POJ-1724 深搜剪枝

    这道题目如果数据很小的话.我们通过这个dfs就可以完成深搜: void dfs(int s) { if (s==N) { minLen=min(minLen,totalLen); return ; } ...

随机推荐

  1. Extended VM Disk In VirtualBox or VMware (虚拟机磁盘扩容)

    First, Clean VM all snapshot, and poweroff your VM. vmdk: vmware-vdiskmanager -x 16GB myDisk.vmdk vd ...

  2. linux-指定特殊域去重

    测试数据: 2017-10-24 14:14:11:1123 [ INFO] order_type=add,order_id=9152017-10-24 14:14:11:1123 [ INFO] o ...

  3. vmware 安装 Mac OS X 10.9 Mavericks

    This guide shows how to install fresh OS X 10.9 Mavericks on VMware workstation with Windows 7 or Wi ...

  4. 顶点纹理shader

    Shader "Custom/VertDisplace" { Properties { _MainTex ("Base (RGB)", 2D) = " ...

  5. make clean、make mrproper、make distclean的区别【转】

    本文转载自:http://blog.csdn.net/liyayao/article/details/6818061 内核编译时, 到底用make clean, make mrproper还是make ...

  6. spring applicationContext.xml 配置文件 详解

      <?xml version="1.0" encoding="UTF-8"?>   <beans xmlns="http://ww ...

  7. PHP之Composer类库依赖管理神器

    Composer中文版说明见:https://github.com/kaka987/Composer-zh Composer 是PHP的类包依赖管理工具,用它可以轻松的引用第三方类包,类似于node的 ...

  8. 题目1006:ZOJ问题(递推规律)

    题目链接:http://ac.jobdu.com/problem.php?pid=1006 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  9. sencha touch routes(路由) 传递中文参数

    使用路由的时候可以传递参数 如下: index.html#eaterylist/335/61/61/61/B/商户名称 其中6个参数依次是:商户编号/公众账号/微信号/校验号/服务类型/商户名称 因为 ...

  10. centos 7安装jdk、tomcat

    jdk安装 创建上传目录: [root@ckl1 home]# pwd /home [root@ckl1 home]# mkdir upload 安装上传工具: yum install lrzsz 上 ...