HDU1010 Tempter of the Bone dfs(奇偶减枝)
直接搜索会超时,需要减枝(奇偶减枝)。
#include<stdio.h> #include<string.h> int n,m,t; char map[7][7]; int x0,y0,x1,y1; int flag; int abs(int a) {a>0?:a=-a; return a; } void dfs(int time,int x,int y) {int temp=time-(abs(x1-x)+abs(y1-y));if(temp<0||temp%2) return;//剩余时间-距离终点的最小步数 小于0(够不到终点)或者 为奇数(最多能到终点前一个位置)则返回 else if(time==0) {if(x==x1&&y==y1)flag=1;else return; }if(flag) return;if(x-1>=0&&map[x-1][y]!='X'){map[x-1][y]='X'; dfs(time-1,x-1,y);map[x-1][y]='.'; }if(y-1>=0&&map[x][y-1]!='X'){map[x][y-1]='X';dfs(time-1,x,y-1);map[x][y-1]='.'; }if(x+1<n&&map[x+1][y]!='X'){map[x+1][y]='X';dfs(time-1,x+1,y);map[x+1][y]='.'; }if(y+1<m&&map[x][y+1]!='X'){map[x][y+1]='X';dfs(time-1,x,y+1);map[x][y+1]='.'; }return; } int main(void) {int count;while(scanf("%d%d%d",&n,&m,&t)) {if(n==0&&m==0&&t==0) break;flag=0;count=0;getchar();for(int i=0;i<n;i++){for(int j=0;j<m;j++){scanf("%c",&map[i][j]); if(map[i][j]=='S'){x0=i;y0=j; map[i][j]='X'; } if(map[i][j]=='D'){x1=i;y1=j; count++; } if(map[i][j]=='.') count++;}getchar();}if(t>count||t<abs(x1-x0)+abs(y1-y0)){printf("NO\n");continue; }dfs(t,x0,y0);if(flag) printf("YES\n");else printf("NO\n"); } }
转载于:https://www.cnblogs.com/lqquan/p/3671870.html
HDU1010 Tempter of the Bone dfs(奇偶减枝)相关推荐
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- HDU1010 Tempter of the Bone DFS+剪枝
点击打开链接 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdu1010 Tempter of the Bone
转载自:http://acm.hdu.edu.cn/forum/read.php?tid=6158 sample input: 4 4 5 S.X. ..X. ..XD .... 问题: (1): 在 ...
- HDU1010 Tempter of the Bone(DFS奇偶剪枝)
传送门 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. Howe ...
- HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...
- (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...
- hdu1010 Tempter of the Bone
题目意思: 一只吉娃娃去迷宫捡骨头, 捡到骨头后发现是一个陷阱, 然后就想逃出迷宫:迷宫是N*M 规格的, 迷宫只有一道门且 只在第 T 秒钟开一会儿(少于1秒) 也就是说只在[ t, t+1) ...
- 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
1) 题目 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
最新文章
- xBIM 实战01 在浏览器中加载IFC模型文件
- Valve className=org.apache.catalina.valves.AccessLogValve directory=logs prefix=localhost_acce
- 理解图像的傅里叶变换(细心分析)
- 人工智能化发展已经到了哪一步?
- 华容道6×6图解_2008款马自达6仪表盘图解,仪表盘故障指示灯图解
- 女子800米跑进4分30秒才合格,茅台回应应聘者需体测...
- Part 1——使用 Go Modules
- PostgreSQL逻辑优化——整体架构
- JavaScript 中的单例模式 (singleton in Javascript)
- Bex5文档服务器,不通过登录直接打开BeX5的首页和功能页的url是什么?
- 【数学建模】层次分析法(AHP)
- 云计算和虚拟化 - 虚拟化的介绍
- 在 ABT 节点部署 RPG 制作大师游戏指南 | ArcBlock 博客
- [古文观止]《相州昼锦堂记》(宋·欧阳修)
- Web前端-Vue中给input框赋值
- java格林威治时间转换_JAVA 格式化格林威治时间(Wed Aug 01 00:00:00 CST 2012)格式转换...
- Discuz! 模板制作
- js的tree转数组
- Intel处理器分类规则
- 使用Authorize.net的SDK实现符合PCI标准的支付流程
热门文章
- Linux df -h查看磁盘使用情况
- Redis Bloom布隆过滤器的安装及使用
- Spring AOP编程-传统AOP开发切点表达式写法介绍
- MATLAB中将pgm图片二值化
- python with语句_python中的with语句
- Linux C:文件描述符、IO重定向、恢复标准输入输出
- signal.h 中的宏定义 SIG_DFL 及 SIG_IGN
- 用WT516P6Core离线语音模块在烧录和连接MCU时要注意避开的坑,要不挠掉头发也钻不出来!我差点套进去了,还好他们技术人员给力!把我给扯出来了!做了一个踩坑记录分享给大家
- linux进程网络均衡,linux多CPU进程负载均衡解析
- 华为真的注册鸿蒙,“鸿蒙”真的来了!华为注册了整本山海经?