看了好多别人的  代码,最终还是 感觉 这种代码的风格适合我  下面附上代码

 /* 首先 应该充满信心!  先写出来 自己的程序  然后慢慢改 ,
如果是 答题思路错误的话 借鉴别人的 代码 再写
*/
/*没有剪枝 时间超限*/
#include<stdio.h>
#include<string.h>
char a[][];
int visited[][];
int s[][]={-,,,,,-,,};
int n,m,t,bx,by,cx,cy,step=,mark;
void DFS(int y,int x,int step) // 传输 进去现在 的 位置 并且传出过去 已有的 步数
{
if(y==cy&&x==cx&&step==t)
{
mark=;
}
visited[y][x]=;
for(int i=;i<;i++)
{
if(a[y+s[i][]][x+s[i][]]!='X'&&(y+s[i][])>=&&(y+s[i][])<n&&(x+s[i][])>=&&(x+s[i][])<m&&!visited[y+s[i][]][x+s[i][]]) // 不超界 并且 不是墙 而且没有访问
{
step++;
DFS(y+s[i][],x+s[i][],step);
step--;
} }
visited[y][x]=;
}
int main()
{
int i,j;
while(scanf("%d%d%d",&n,&m,&t)!=EOF)
{
if(n==&&m==&&t==)
break
getchar();
memset(visited,,sizeof(visited));
for(mark=step=i=;i<n;i++)
{
for(j=;j<m;j++)
{
scanf("%c",&a[i][j]);
if(a[i][j]=='S') // 找到进入的坐标
{
bx=j;
by=i;
}
if(a[i][j]=='D') // 找到出去的坐标
{
cx=j;
cy=i;
}
}
getchar();
}
DFS(by,bx,); // 传输 当前座标
if(mark!=)
printf("NO\n");
else
printf("YES\n");
}
return ;
}

上面的 没有剪枝  时间超限   下面开始 剪枝  .

 /* 首先 应该充满信心!  先写出来 自己的程序  然后慢慢改 , 如果是 答题思路错误的话 借鉴别人的 代码 再写  */
/*
剪枝:
1: 奇偶剪枝:到终点的最短步数(就算需要绕路也没事要的奇偶) 和 到终点限定的步数 如果 奇偶性不同的话是不可能达到的 (绕路是同时多出偶数倍的步数) 1/2 的时间
2: 进去的时候 到 终点的最短路 如果大于 给定的步数 也不可能 . (也可能绕路绕超所以需要重复)
3: 可以走的格子 走完但是仍然还不够限定的步数 就不行了
*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
#include<limits.h>
#define leng 10
using namespace std;
char a[leng][leng];
int ex,ey,n,m,t,bx,mark,by,b[][]={,,,,,-,-,},visited[leng][leng];
void DFS(int y,int x,int step)
{
int d=t-step-abs(y-ey)-abs(x-ex); // 剩下 的步数 - 到终点的步数 小于 0 完蛋 .
if(t<step||mark==||d<||d%) // 这里三个 剪枝 . 上述公式 如果不是 偶数的话 , 就完蛋.
return;
if(a[y][x]=='D'&&t==step)
{
mark=;
}
visited[y][x]=;
for(int i=;i<;i++)
{
int tx=x+b[i][],ty=y+b[i][];
if(a[ty][tx]!='X'&&tx>=&&tx<m&&ty>=&&ty<n&&!visited[ty][tx]) // 不是 墙 不超界 没用过
{
DFS(ty,tx,step+);
}
}
visited[y][x]=;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&t),!(n==m&&m==t&&t==))
{
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
scanf(" %c",&a[i][j]);
if(a[i][j]=='S')
{
bx=j;
by=i;
}
if(a[i][j]=='D')
{
ex=j;
ey=i;
}
}
}
memset(visited,,sizeof(visited));
mark=;
DFS(by,bx,);
if(mark==)
printf("NO\n");
else
printf("YES\n");
}
return ;
}

Tempter of the Bone------剪枝的更多相关文章

  1. hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)

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

  2. hdu 1010:Tempter of the Bone(DFS + 奇偶剪枝)

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

  3. hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】

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

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

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

  5. Tempter of the Bone(dfs奇偶剪枝)

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

  6. HDU 1010 Tempter of the Bone【DFS经典题+奇偶剪枝详解】

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

  7. Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏

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

  8. HDU1010:Tempter of the Bone(dfs+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010   //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...

  9. Tempter of the Bone(dfs+奇偶剪枝)题解

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

  10. HDU 1010:Tempter of the Bone(DFS+奇偶剪枝+回溯)

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

随机推荐

  1. 第一章 Linux命令行简介

    1 Linux系统命令操作语法的格式 命令_[参数选项]_[文件或路径]    其中 _ 至少一个空格    如:rm -f /etc/hosts    其中/etc/hosts完整路径不带空格   ...

  2. Platform 获取主机系统信息

    该模块用来访问平台相关属性. 常见属性和方法 1. import platform(pip install platform)   2.获取操作系统名称及版本号 def get_platform(): ...

  3. Centos6文本安装教程

    Centos6.4文本方式安装 虚拟机中文本安装(内存512),内存大于512默认为图形安装 1.选择安装媒体,在vbox中选skip跳过 2.选择安装语言(chinese(simplifired)简 ...

  4. Python pygame库的应用

    今天想用pygame库写一个击打外星人飞船的python程序 这个游戏的效果是操纵一个位于屏幕底端的飞船,通过上下左右控制飞船移动方向,按空格发射子弹.游戏中击杀一批飞船后进入下一关卡.每一关卡击打飞 ...

  5. [bzoj3012][luogu3065][USACO12DEC][第一!First!] (trie+拓扑排序判环)

    题目描述 Bessie has been playing with strings again. She found that by changing the order of the alphabe ...

  6. POJ 2142 TheBalance 模线性方程求解

    题目大意: 就是将两种砝码左右摆放,能够在物品放置在天平上时保持平衡 很容易得到 ax + by = t的模线性方程 按题目要求,希望首先满足 |x| + |y| 最小 , 如果有多种情况,再满足所有 ...

  7. 武大OJ 622. Symmetrical

    Description          Cyy likes something symmetrical, and Han Move likes something circular. Han Mov ...

  8. HDFS v1.0学习笔记

    hdfs是一个用于存储大文件的分布式文件系统,是apache下的一个开源项目,使用java实现.它的设计目标是可以运行在廉价的设备上,运行在大多数的系统平台上,高可用,高容错,易于扩展. 适合场景 存 ...

  9. Python3基础(六) 深入list列表

    正如Python FAQ1附录中说的, Python中任何值都是一个对象,所以任何类型(int.str.list-)都是一个类.而类就必然有它的方法或属性,我们要记下这么多类的所有方法显然是不可能的, ...

  10. Cisco VPP(1) 简单介绍

    一.简单介绍 VPP全称Vector Packet Processing.是Cisco2002年开发的商用代码. 2016年2月11号,Linux基金会创建FD.io项目.Cisco将VPP代码的开源 ...