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#——数据库的访问
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 11-c++虚拟函数
虚拟函数 #include "stdio.h" class A{ public: void print() { printf("%s","this i ...
- Centos7搭建nginx并提供外网访问
搭建nginx之后,80端口,其他机器无法访问 查询端口是否开启 firewall-cmd --query-port=80/tcp 永久开放80端口 firewall-cmd --permanent ...
- ICMP,ARP协议
ICMP ICMP是(Internet Control Message Protocol)Internet控制报文协议.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制消息.控制 ...
- node里读取命令行参数
一.process.env process.env属性返回一个包含用户环境信息的对象. 最常见的需求,前端需要根据不同的环境(dev,prd),来调用不同的后端接口.如果用webpack,是这么做的: ...
- C#工具帮助类
md5帮助类 .引入库 using System.Security.Cryptography;//引用Md5转换功能 .计算字符串的Md5值 public static string GetMD5Wi ...
- Oracle ASM注意事项
ASM是负载均衡的存储策略,加新磁盘会将其它盘数据平均迁移到新磁盘,删除磁盘会将删除磁盘数据平均写回其它磁盘 1.同一磁盘组如果是在raid上,划分的磁盘越少越好,磁盘组分布在不同raid上性能好: ...
- jQuery匹配id 批量修改css属性
<ul id="foreignCurrencyTree_1_ul"> <li id="foreignCurrencyTree_11_li"&g ...
- 6)STM32使用HAL库实现modbus的简单通讯
1.判断地址.校验 2.读取本机数据并校验打包 3.发送数据包 4.本机数据长度比要读取的长度短怎么办 4.校验错误怎么办
- android 彩信附件添加删除
http://blog.csdn.net/yuzhu_guan2012/article/details/6679154