HDU1010-奇偶剪枝(DFS)
题目链接:Tempter of the Bone
第一次做剪枝的题目,剪枝,说实话研究的时间不短。好像没什么实质性的进展,遇到题目。绝对有会无从下手的感觉,剪枝越来越神奇了。
。。
。
HDU1010一道剪枝的经典题目,自己当初想用BFS过。提交了10几遍WA,后来查了是剪枝最终死心了
PS:第一次写剪枝题目,用了一个模拟地图来做奇偶性的判定条件进行剪枝,大牛们写的那种俺实在看不懂。渣渣儿。
。
。。
代码有点挫。
。
。
。562ms低空掠过
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
char ma[10][10];
bool vis[10][10];
bool mapp[10][10] = {{0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0,1},{1,0,1,0,1,0,1,0,1,0},{0,1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1,0}};
int n,m,T,dx,dy;
bool flag;
int mv[4][2]={{1,0},{0,-1},{0,1},{-1,0}};
void dfs(int sx,int sy,int dp)
{
if(dp==T&&sx==dx&&sy==dy)
{
flag=1; return ;
} if(flag) return; int t = T - dp;
if(mapp[sx][sy]==mapp[dx][dy]) //奇偶剪枝
{
if(t % 2) return ;
}
else
{
if(t % 2==0)
return ;
}
for(int i=0;i<4;i++)
{
int xx = sx + mv[i][0];
int yy = sy + mv[i][1];
if(ma[xx][yy]!='X' && vis[xx][yy]!=1 &&0<=xx && xx<n && 0<=yy && yy<m)
{
vis[xx][yy] = 1;
dfs(xx,yy,dp+1);
vis[xx][yy] = 0;
}
}
return;
}
int main()
{
int sx,sy;
while(~scanf("%d%d%d",&n,&m,&T))
{
if(n==0&&m==0&&T==0) break;
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
scanf("%s",ma[i]);
for(int j=0;j<m;j++)
{
if(ma[i][j]=='S')
{ sx=i; sy=j; }
else if(ma[i][j]=='D')
{ dx=i; dy=j; }
}
}
flag=0;
vis[sx][sy] = 1;
dfs(sx,sy,0);
(flag==1)? puts("YES"):puts("NO");
}
return 0;
}
HDU1010-奇偶剪枝(DFS)的更多相关文章
- hdoj1010 奇偶剪枝+DFS
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】
Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- 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 ...
- 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 ...
- HDU 1010 (DFS搜索+奇偶剪枝)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...
- 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 ...
- 杭电1010(dfs + 奇偶剪枝)
题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...
- HDU 1010Tempter of the Bone(奇偶剪枝回溯dfs)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- C#用Microsoft.Office.Interop.Word进行Word转PDF的问题
之前用Aspose.Word进行Word转PDF发现'\'这个字符会被转换成'¥'这样的错误,没办法只能换个方法了.下面是Microsoft.Office.Interop.Word转PDF的方法: p ...
- crontab的使用
基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...
- Android基础TOP2_1:输出系统时间
Activity: <TextView android:id="@+id/tv" android:layout_width="wrap_content" ...
- webstorm进行VisualSVN配置及上传项目到项目库
以前建站一直都是自己一个人,最近要做一个比较大的网站,寻思着利用svn在整个开发过程中会比较快,于是摸索着配置了一下. 首先,下载VisualSVN这个软件,官网链接 https://www.visu ...
- html5——2D转换
transform 属性 1.向元素应用 2D 或 3D 转换 2.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 缩放与位移 transform: scale(, 0.5);//水平缩放,垂直缩放 ...
- C# Tuple 创建一个新二元集合
List<string> list1=new List<string>(); List<string> list2=new List<string>() ...
- PHP 之递归遍历目录与删除
/** * @Description: 递归查询目录文件 * @Author: Yang * @param $path * @param int $level * @return array */ f ...
- zoom,zoom与haslayout的关系,zoom与transform: scale( )的区别
1.zoom:(缩放)
- TP调用JS
echo "<script>alert('删除成功');window.location.href='?c=Banner&a=index' </script>& ...
- centos7安装个人网盘owncloud
现在个人资料越来越重要,网络速度也已经满足日常需要,网盘已经是生活着存取个人数据不可缺少的工具. 下面在linxu centos7下面安装owncloud搭建自己私人网盘: 1.新建一个账号用来安装个 ...