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 ...
随机推荐
- cocos2dx实现单机版三国杀(二)
接上续,东西还没有做完 所以代码免不了改动 之前的头文件现在又改了不少,因为架构也改变了现在主要类就是GameScene.GameUI.PlayInfo.Poker这四个类 前面想的GameLoop ...
- JQuery文档加载完成执行js的几种方法
js中文档加载完毕.一般在body加一个onload事件或者window.onload = function () {} jQuery中有好多写法,平时也不注意,别人一问,还真觉得头大. 下面是我整理 ...
- SPPNet论文翻译-空间金字塔池化Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition
http://www.dengfanxin.cn/?p=403 原文地址 我对物体检测的一篇重要著作SPPNet的论文的主要部分进行了翻译工作.SPPNet的初衷非常明晰,就是希望网络对输入的尺寸更加 ...
- 【sqli-labs】 less44 POST -Error based -String -Stacked Blind(POST型基于盲注的堆叠字符型注入)
盲注漏洞,登陆失败和注入失败显示的同一个页面 可以用sleep函数通过延时判断是否闭合引号成功 这个方法有一点不好的地方在于,并不能去控制延时,延时的时间取决于users表中的数据数量和sleep函数 ...
- Centos6.7 安装Naigos教程
Centos6.7 安装Naigos教程参考文档:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickst ...
- appium 使用send_keys方法时报错: driver.find_element_by_id("com.hmkx.zgjkj:id/layout_search_bar_input").send_keys("123")
新手 使用send_keys方法时一直报错,上网查这个方法的用法,看着大家都是这么写的啊,后来直接搜索 报错信息,搜索结果的针对性就清楚多了. 原来是seleium版本太高导致的问题. 可以先在cmd ...
- B.4 集
在.NET 3.5之前,框架中根本没有公开集(set)集合.如果要在.NET 2.0中表示集,通常会 使用 Dictionary<,> ,用集的项作为键,用假数据作为值..NET3.5的 ...
- Python模块 os.walk
Os.walk os.walk(top,topdown=True,onerror=None,followlinks=False) os.walk()是python中内置(built-in)的目录树生成 ...
- 第四节:numpy之数组排序
- 第三节:初识pandas之DataFrame(上)
DataFrame是Python中Pandas库中的一种数据结构,它类似excel,是一种二维表.