题目链接: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)的更多相关文章

  1. hdoj1010 奇偶剪枝+DFS

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

  2. HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】

    Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  3. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...

  4. 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 ...

  5. 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 ...

  6. HDU 1010 (DFS搜索+奇偶剪枝)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...

  7. 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 ...

  8. 杭电1010(dfs + 奇偶剪枝)

    题目: The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked ...

  9. HDU 1010Tempter of the Bone(奇偶剪枝回溯dfs)

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

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

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

随机推荐

  1. python--9、并发之多进程应用

    multiprocessing模块 想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.Python提供了multiprocessing.  ...

  2. React Native常用组件在Android和IOS上的不同

    React Native常用组件在Android和IOS上的不同 一.Text组件在两个平台上的不同表现 1.1 height与fontSize 1.1.1只指定font,不指定height 在这种情 ...

  3. MFC SkinMagic使用方法

    皮肤库下载地址 https://pan.baidu.com/s/1IuiYlFUJIi-TS9Cgz3M6RA 1.创建MFC工程 2.然后把corona.smf.SkinMagic.dll.Skin ...

  4. log4net 局部代码 看不懂....

    public interface ILogger {} public interface ILoggerWrapper { ILogger Logger {get;} } public interfa ...

  5. 扩增子分析QIIME2-4分析实战Moving Pictures

    本示例的的数据来自文章<Moving pictures of the human microbiome>,Genome Biology 2011,取样来自两个人身体四个部位五个时间点   ...

  6. react 父组件调用子组件方法

    import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...

  7. SqlServer 【基 本 操 作】

    1.Row_Number() select * from (select Row_Number() over (order by FSalary) as 'RowNum' ,* from dbo.T_ ...

  8. 四、Spider用法

    本文转载自以下链接: https://scrapy-chs.readthedocs.io/zh_CN/latest/topics/spiders.html https://doc.scrapy.org ...

  9. wget扒网站

    wget神奇操作   整站复制 只限静态网页 wget -P 指定下载路径 -p 获取显示HTML页面所需的所有图像 -k  使链接指向本地文件 -H  递归时转到外部主机. wget --mirro ...

  10. namespace的作用及用法

    namespace 所谓namespace,是指标识符的可见范围.C++标准库中的所有标识符都被定义在一个名为 std 的namespace 中. 一.<iostream>和<ios ...