题意:输入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. 利用Visio绘制数据流图与组织结构图

    绘制数据流图: 利用Visio 2007来绘制网上书店系统的数据流图.利用Visio 2007创建Gane- Sarson数据流图,可以选择“软件和数据库”模板,然后再选择“数据流模型图”,创建之后可 ...

  2. 关于MySQL数据库

    MySQL最流行的关系型数据库管理系统 MySQL官网:http://www.mysql.com MySQL是WEB应用方面最好的RDBMS应用软件之一 RDBMS:Relational Databa ...

  3. Mysql主从热备

    mysql主从配置比较不错的文章,大家可以参考下~ https://www.cnblogs.com/kissdodog/p/5422195.html

  4. jquery 强大表格插件 DataTables

    官网:https://datatables.net/ 配置:https://datatables.net/reference/option/ API :https://datatables.net/r ...

  5. CopyTransform

    // TransformCopier.cs v 1.1 // homepage: http://wiki.unity3d.com/index.php/CopyTransform using Unity ...

  6. Android5.x新特性之 Toolbar和Theme的使用

    Toolbar 你还在为Android 的ActionBar的文字不能随意设置位置而烦恼么?你还在为ActionBar不能自定义添加自己的布局而烦恼么?现在告诉你一个好消息,当你看到这篇文章时,就不必 ...

  7. 浅谈千万级PV/IP规模高性能高并发网站架构

    高并发访问的核心原则其实就一句话“把所有的用户访问请求都尽量往前推”. 如果把来访用户比作来犯的"敌人",我们一定要把他们挡在800里地以外,即不能让他们的请求一下打到我们的指挥部 ...

  8. Glide加载图片缓存库出现——You cannot start a load for a destroyed activity

    请记住一句话:不要再非主线程里面使用Glide加载图片,如果真的使用了,请把context参数换成getApplicationContext.

  9. EventHandler 与常见的.Net预定义委托

    看着下面这两句事件定义及激发忽然有点不明白了, public event EventHandler<ExternalDataEventArgs> Submit; Submit(null, ...

  10. 【图算法】Dijkstra算法及变形

    图示: 模版: /* Dijkstra计算单源最短路径,并记录路径 m个点,n条边,每条边上的权值非负,求起点st到终点et的最短路径 input: n m st et 6 10 1 6 1 2 6 ...