hdu 1010 Tempter of the Bone
来源:互联网 发布:js toggle 切换状态 编辑:程序博客网 时间:2024/06/06 12:52
搜索,关键在于减枝
#include<iostream>#include<cstring>#include<cmath>using namespace std;int n,m,t,flag;char mapp[10][10];int visit[10][10];int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};void dfs(int x,int y,int num){if(mapp[x][y]=='D'&&num==t){flag=1;return;}else if(mapp[x][y]!='D'&&num>=t) return;visit[x][y]=1;num++;for(int i=0;i<4;i++){int xx=x+dir[i][0],yy=y+dir[i][1];if(xx>=0&&xx<n&&yy>=0&&yy<m&&mapp[xx][yy]!='X'&&!visit[xx][yy]){dfs(xx,yy,num);if(flag) return;//找到之后就不要再找了 visit[xx][yy]=0;}}}int main(){while(cin>>n>>m>>t&&n&&m&&t){flag=0;int x,y;int ex,ey;for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>mapp[i][j];if(mapp[i][j]=='S') x=i,y=j;if(mapp[i][j]=='D') ex=i,ey=j;}}if(abs(ex-x)+abs(ey-y)>t||(x+ex+y+ey+t)%2==1)//减枝 {cout<<"NO"<<endl;continue;}memset(visit,0,sizeof(visit));dfs(x,y,0);if(flag){cout<<"YES"<<endl;}else {cout<<"NO"<<endl;}}return 0;}
0 0
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU-1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- hdu 1010 Tempter of the Bone
- java内存管理
- 二叉树遍历的6种遍历方法
- 地址空间
- 位域的使用
- C++强制类型转换
- hdu 1010 Tempter of the Bone
- 扑克序列——第五届蓝桥杯省赛C语言A组第6题
- 什么是#pragma?
- 图像验证码识别(六)——图像中的直线检测
- CGI, FCGI, SCGI, WSGI 释异
- 编程小技巧
- Ash数学运算
- tomcat的配置
- Git安装与配置