zoj 2110(hdu 1010)Tempter of the Bone(深搜)
来源:互联网 发布:android关于网络面试题 编辑:程序博客网 时间:2024/05/18 03:11
一道很陈的搜索题了,深搜实现的,但我还是发现了一些之前没有注意的地方……
第一,全局变量的赋值应该注意……………………。
第二,就是搜索的优化剪枝问题,这种题很容易超时。
下面是代码:
#include<stdio.h>#include<string.h>#include<math.h>int dir[4][2]={-1,0,1,0,0,1,0,-1};int n,m,t,si,sj,di,dj,wall=0,flag=0;char map[9][9];void getmap(){int i,j;wall=0;for(i=0;i<n;i++)for(j=0;j<m;j++){scanf("%1s",&map[i][j]);if(map[i][j]=='S'){ si=i; sj=j; }if(map[i][j]=='D'){ di=i; dj=j; }if(map[i][j]=='X')wall++;}}void dfs(int a,int b,int cnt){int i,temp;if(a<0||b<0||a>n-1||b>m-1)return;if(a==di&&b==dj&&cnt==t) flag=1;if(flag) return;temp=t-cnt-abs(a-di)-abs(b-dj); //剪枝if(temp<0||temp&1)return; //temp为负数或奇数时,无法到达for(i=0;i<4;i++){if(map[ a+dir[i][0] ][ b+dir[i][1] ]!='X'){map[ a+dir[i][0] ][ b+dir[i][1] ]='X';dfs(a+dir[i][0],b+dir[i][1],cnt+1);map[ a+dir[i][0] ][ b+dir[i][1] ]='.';}}return;}int main(){while(scanf("%d%d%d",&n,&m,&t),n){wall=0;getmap();if(n*m-wall-1<t) //剪枝{printf("NO/n");continue;}flag=0;map[si][sj]='X';dfs(si,sj,0);if(flag==1) printf("YES/n");else printf("NO/n");}return 0;}
- zoj 2110(hdu 1010)Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone (ZOJ 2110) DFS+剪枝
- hdu 1010 Tempter of the Bone(深搜)
- HDU 1010 Tempter of the Bone(深搜)
- zoj 2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone
- Zoj 2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone
- ZOJ:2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone
- ZOJ - 2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone
- ZOJ 2110 Tempter of the Bone
- zoj 2110 || hdoj 1010 Tempter of the Bone(DFS)
- ZOJ 2110 ( HDU 1010 ) Tempter of the Bone( 比较经典的DFS) --from lanshui_Yang
- ZOJ 2110(HDU 1010) Tempter of the Bone(经典剪枝-奇偶剪枝)
- HDU 1010 && ZOJ 2110 Tempter of the bone (DFS + 奇偶剪枝)
- CDMA iphone 4 ESN Imei
- 跨平台event分析
- Ipad越狱后无法使用VPN的解决方法
- Wince下 Dun 拨号上网(AP)
- (详解)Eclipse3.6搭建 Android 2.2 开发环境(转)
- zoj 2110(hdu 1010)Tempter of the Bone(深搜)
- win7下鼠标突然没反应了
- 关于JAVA和Android的JNI的使用
- 教育网IP网段(部分)
- Flex中的嵌入资源
- Java 理论与实践: 变还是不变
- Hashtables - When you create your own key object in a Hashtable, be careful
- Fedora/Linux 下免公钥安装软件
- hashmap和hashtable