HDU 1010——Tempter of the Bone
来源:互联网 发布:大数据修炼系统女主 编辑:程序博客网 时间:2024/06/06 05:26
深搜
注意剪枝。
#include<iostream>#include<cstdio>using namespace std;int flag;char map[10][10];int X,Y,t;int n,m;int dir[4][2]={1,0,-1,0,0,1,0,-1};void dfs(int x,int y,int time){if(x==X&&y==Y&&time==t){flag=1;return;}if(time>t)return;if((t-time)%2!=(abs(X-x)+abs(Y-y))%2)return;if(flag)return;int i;for(i=0;i<4;i++){int u,v;u=dir[i][0]+x;v=dir[i][1]+y;if(u<n&&u>=0&&v<m&&v>=0&&map[u][v]!='X'){map[u][v]='X';dfs(u,v,time+1);map[u][v]='.';}}}int main(){int x,y;while(cin>>n>>m>>t&&(n||m||t)){int i,j;int k=0;for(i=0;i<n;i++){for(j=0;j<m;j++){cin>>map[i][j];if(map[i][j]=='.')k++;if(map[i][j]=='S'){x=i;y=j;map[i][j]='X';//注意}if(map[i][j]=='D'){X=i;Y=j;}}}if(t-1>k){cout<<"NO"<<endl;continue;}flag=0;dfs(x,y,0);if(flag)cout<<"YES"<<endl;elsecout<<"NO"<<endl;}return 0;}
- hdu 1010——Tempter of the Bone(DFS)
- HDU 1010——Tempter of the Bone
- 【剪枝】HDU 1010——tempter of the bone
- hdu——1010Tempter 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
- 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
- cygwin安装ruby1.9.3
- Qt程序设计——实现以项目管理文件的功能:创建和打开项目
- 比较C++中的4种类型转换方式
- HDU 4151The Special Number(暴力+二分)
- Linux Kernel Development——定时器和时间管理
- HDU 1010——Tempter of the Bone
- Ant(1)
- Win7系统下解决魔兽争霸全屏问题
- 转置
- C++标准库 Numeric limits climits cfloat cstdint
- 虚拟机下Ubuntu修改root密码
- web项目中的乱码问题的原因及解决办法
- Windows Phone 7使用本地数据库
- 开发者需知的10类工具