HDU 1010 Tempter of the Bone【DFS】
2015-02-05 15:53
316 查看
学习剪枝的第一篇@_@
学习别人的剪枝,一剪就是两天@_@----
参看的这篇--
/article/2392039.html
自己的小体会--
奇偶剪枝可以举两个一般的例子
比如样例
S.X.
..X.
..XD
....
转化为所需要的步数
S 6 X 2
6 5 X 1
5 4 X D
4 3 2 1
可以看到步数为奇数的时候,所需要的时间也为奇数
步数为偶数的时候,需要的时间也为偶数(因为是一秒走一步)
学习别人的剪枝,一剪就是两天@_@----
参看的这篇--
/article/2392039.html
自己的小体会--
奇偶剪枝可以举两个一般的例子
比如样例
S.X.
..X.
..XD
....
转化为所需要的步数
S 6 X 2
6 5 X 1
5 4 X D
4 3 2 1
可以看到步数为奇数的时候,所需要的时间也为奇数
步数为偶数的时候,需要的时间也为偶数(因为是一秒走一步)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<math.h> using namespace std; int n,m,t,flag,di,dj,wall; int dir[4][2]={{0,-1},{0,1},{-1,0},{1,0}}; char map[10][10]; void dfs(int si,int sj,int cnt) { int tem; if(si<=0||sj<=0||si>n||sj>m) return; if(si==di&&sj==dj&&cnt==t) flag=1; if(flag) return; tem=t-cnt-abs(di-si)-abs(dj-sj); if(tem<0||tem%2) return; for(int i=0;i<4;i++) { if(map[si+dir[i][0]][sj+dir[i][1]]!='X') { map[si+dir[i][0]][sj+dir[i][1]]='X'; dfs(si+dir[i][0],sj+dir[i][1],cnt+1); map[si+dir[i][0]][sj+dir[i][1]]='.'; } } return; } int main() { int si,sj; while(scanf("%d %d %d",&n,&m,&t)!=EOF&&n&&m&&t) { wall=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>map[i][j]; if(map[i][j]=='S') {si=i;sj=j;} else if(map[i][j]=='D') { di=i;dj=j;} else if(map[i][j]=='X') wall++; } } if(n*m-wall<=t) { printf("NO\n"); continue; } flag=0; map[si][sj]='X'; dfs(si,sj,0); if(flag) printf("YES\n"); else printf("NO\n"); } }
相关文章推荐
- HDU 1010 Tempter of the Bone(DFS)
- hdu1010 Tempter of the Bone (DFS)
- (step4.3.1) 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) 奇偶剪枝
- (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
- hdu 1010 Tempter of the Bone (dfs+剪枝)
- HDU 1010 Tempter of the Bone (dfs + 剪枝)
- HDU1010 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 &&ZOJ 2110【DFS】
- hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)