HDU 1010 Tempter of the Bone (DFS)
来源:互联网 发布:淘宝订单如何申请退款 编辑:程序博客网 时间:2024/05/13 08:06
因为要求不是最快到达,而是在T时刻正好到达,所以不能用BFS搜。DFS注意剪枝,如果剩余时间和剩余步数奇偶性不同的话要减掉。
//Memory: 232 KB//Time: 687 MS#include <stdio.h>#include <string.h>#include <math.h>char map[10][10];bool vis[10][10];int dx,dy,n,m,time;int d[4][2]={1,0,0,1,-1,0,0,-1};bool flag;void dfs(int x,int y,int t){if((x+y+dx+dy)%2 != t%2)return;if(t==0)return;if(flag)return;vis[x][y]=true;int k=0,xt,yt;for(k=0;k<4;k++){xt=x+d[k][0];yt=y+d[k][1];if(xt>=1 && xt<=n && yt>=1 && yt<=m )if(map[xt][yt]!='X' && !vis[xt][yt]){if(dx==xt && dy==yt && t==1)flag=true;else{dfs(xt,yt,t-1);}if(flag)return;}}vis[x][y]=false;}int main(){while(scanf("%d%d%d",&n,&m,&time)!=EOF){if(n==0 && m==0 && time==0)break;flag=false;memset(vis,false,sizeof(vis));int i,j;int st,sy;getchar();for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%c",&map[i][j]);if(map[i][j]=='S'){st=i;sy=j;}if(map[i][j]=='D'){dx=i;dy=j;}}getchar();}dfs(st,sy,time);if(flag)printf("YES\n");elseprintf("NO\n");}return 0;}
- HDU 1010 Tempter of the Bone (DFS)
- HDU 1010 Tempter of the Bone( DFS )
- HDU-1010 Tempter of the Bone (DFS)
- HDU 1010 Tempter of the Bone 【DFS】
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone(dfs)
- hdu 1010 Tempter of the Bone(DFS)
- dfs hdu 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone[dfs]
- [HDU 1010] Tempter of the Bone DFS
- HDU 1010 Tempter of the Bone(DFS)
- HDU 1010 Tempter of the Bone(DFS)
- hdu 1010 Tempter of the Bone dfs
- hdu 1010Tempter of the Bone(DFS)
- HDU-1010-Tempter of the Bone【DFS】
- hdu-1010Tempter of the Bone-dfs
- hdu 1010 Tempter of the Bone (dfs)
- HDU 1010 Tempter of the Bone(dfs)
- Java_各种Exception解析
- 详细介绍Java的内存管理与内存泄露
- 常用软件介绍
- poj_3925 Minimal Ratio Tree
- Bugzilla各种状态详细解释
- HDU 1010 Tempter of the Bone (DFS)
- easerver如何发布web程序
- 软件工程师在职业生涯中说的32句话
- 数据库三范式(上)
- 校门外的树 数据加强版
- Nagle算法, TCP_CORK,TCP_NODELAY,TCP_DEFER_ACCEPT,TCP_QUICKACK
- redis收集整理
- struct ethhdr、ether_header、iphdr、tcphdr、udphdr
- 从 Adobe 官方下载 AS3 Flex3 Flex4 的帮助文档 地址