hdu1010 - dfs,奇偶剪枝】的更多相关文章

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况下走到终点,走过的点不能再走: 题目要点:dfs+奇偶剪枝:输入: 本题用dfs可以做出结果,但是会超时,需要用到就剪枝,来减去大部分的可能: 奇偶剪枝: 方格中起点(tx,ty)和终点(dx, dy)最小步骤是minstep=abs(tx-dx)+abs(ty-dy); 给定步数t,从起点走到终点…
Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggi…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四类元素组成. S'代表是开始位置: 'D'表示结束位置:'.'表示可以走的路:'X'表示是墙. 问:从‘S’  能否在第 t 步 正好走到 'D'. 解题思路: 平常心态做dfs即可,稍微加个奇偶剪枝,第一次做没经验,做过一次下次就知道怎么做了.最后有代码注释解析. AC Code: #includ…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 82702    Accepted Submission(s): 22531 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58766    Accepted Submission(s): 15983 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get ou…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 92175    Accepted Submission(s): 25051 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 135529    Accepted Submission(s): 36393 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 146511    Accepted Submission(s): 39059 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪枝,推断终点和起点的距离与T的奇偶性是否一致,假设不一致,直接剪掉 剪枝2:假设从当前到终点的至少须要的步数nt加上已经走过的步数ct大于T,即nt+ct>t剪掉 剪枝3:假设迷宫中能够走的格子小于T直接剪掉 启示:剪枝的重要性 代码: #include <cstdio> #include…
M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the d…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 107043    Accepted Submission(s): 29107 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
//我刚开始竟然用bfs做,不断的wa,bfs是用来求最短路的而这道题是求固定时间的 //剪纸奇偶剪枝加dfs #include<stdio.h> #include<queue> #include<math.h> #include<string.h> using namespace std; #define N 10 char ma[N][N]; struct node { int x,y,step; }ss,tt; int dis[4][2]={1,0,-…
题意:用一个案例来解释 4 4 5 S.X. ..X. ..XD .... 在这个案例中,是一个4*4的地图. . 表示可走的地方, X 表示不可走的地方,S表示起始点,D表示目标点.没走到一个点之后.这个点就不可走啦.起始点的时间是0,那么问 在 时间刚好是 5 的时候能不能走到 D ,对于这个案例来说显然不能 题解:这里学习到了一个剪枝 : 路径剪枝,是看了这个博客的解释,结合题目讲了两个剪枝,讲得非常具体:tid=6158">http://acm.hdu.edu.cn/forum/r…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 94669    Accepted Submission(s): 25669 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 131057    Accepted Submission(s): 35308 Problem Description The doggie fou…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 110290    Accepted Submission(s): 29967 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep>t剪枝 ②搜到一个解后剪枝 ③当前走到终点最少步数>满足条件还需要走的步数剪枝(关键) ③奇偶剪枝(关键):当前走到终点步数的奇偶性应该与满足条件还需要走的步数奇偶性一致. 其中三四两步放在一步中写:remain=abs(x-ex)+abs(y-ey)-abs(dep-t) 奇偶剪枝的原理:abs(…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89317    Accepted Submission(s): 24279 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
思路: 剪枝的思路参考博客:http://www.cnblogs.com/zibuyu/archive/2012/08/17/2644396.html  在其基础之上有所改进 题意可以给抽象成给出一个图,让你求S点到D点之间是否存在一条长度为T的道路.求两地之间的距离用的是dfs,而dfs在这里的关键是找到回溯的条件,就是当到达D点并且剩余步数为0时,则符合题意的要求,由于我们只需要知道这样一条长度为T的路径是否存在,因此当我们发现存在的时候,只需要将一个全局flag给设置为1即可,然后从此之后…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 55541    Accepted Submission(s): 14983 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 125945    Accepted Submission(s): 33969 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:根据地图,'S'为开始位置,'D'为门的位置,' . '为空地,'X'为墙,不能经过,问:在指定的时间,是否能到达'门'的位置.注意:路不可以重复经过,时间也要刚好是 t ,不能少. 思路: 此处不能用BFS,因为时间要恰好为t,还是得用DFS,不过需要剪枝才能过. 奇偶剪枝: 从一个点到达另外一个点的最短路径长度(时间)可以根据两点坐标求出,路径长度(非最短)与最短路径的长度同奇…
<题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要在某一时刻到达,所以需要用到可行性剪枝中的奇偶剪枝,如果在某一点,它所剩的步数与到终点的最短距离之差是偶数,说明这种情况有可能恰好在规定时刻到达终点,否则不可能,将其剪去. #include <bits/stdc++.h> using namespace std; ][]; ][]; int n,…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 151082    Accepted Submission(s): 40265 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
剪枝是什么,简单的说就是把不可行的一些情况剪掉,例如走迷宫时运用回溯法,遇到死胡同时回溯,造成程序运行时间长.剪枝的概念,其实就跟走迷宫避开死胡同差不多.若我们把搜索的过程看成是对一棵树的遍历,那么剪枝顾名思义,就是将树中的一些“死胡同”,不能到达我们需要的解的枝条“剪”掉,以减少搜索的时间. 这里介绍一下奇偶剪枝 什么是奇偶剪枝? 部分内容来自https://blog.csdn.net/chyshnu/article/details/6171758 把矩阵看成如下形式:  0 1 0 1 0…
奇偶剪枝学习笔记 描述 编辑 现假设起点为(sx,sy),终点为(ex,ey),给定t步恰好走到终点, s | | | + — — — e 如图所示(“|”竖走,“—”横走,“+”转弯),易证abs(ex-sx)+abs(ey-sy)为此问题类中任意情况下,起点到终点的最短步数,记做step,此处step1=8: s — — — — — + | + | + — — — e 如图,为一般情况下非最短路径的任意走法举例,step2=14: step2-step1=6,偏移路径为6,偶数(易证): 结…
http://acm.hdu.edu.cn/showproblem.php?pid=1010 翻译:有只狗被困了,S是起点,D是门,W是墙不能走,‘ . ’是可以走的路,走一次就会在1秒内坍塌,也就是不能停留也不能走回头路,门只在第T秒打开,问是否能逃命? 解题:一开始以为是三维bfs,但是地图上的时间维度是错误的,因为走过一次地面坍塌,只能有一个时间维度.百度找了居然一个bfs都没有,不得不用dfs,无限超时,甚至记忆化搜索也超时.见识到了高端的剪枝. #include<stdio.h> #…
学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.html http://blog.csdn.net/chyshnu/article/details/6171758 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题解:刚开始写直接超时,还没学剪枝,奇偶剪枝... 关于奇偶剪枝 首先举个例子,有…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 144191    Accepted Submission(s): 38474 Problem Description The doggie fou…