HDU 1010 Tempter of the Bone
2012-07-09 11:02
337 查看
题目链接
5Y。。。。居然是因为一个剪枝减导致第一次WA,然后又悲剧了3次,最后感觉自己的程序没啥问题啊,自己乱查 数据,自己想出了一组没有过。。。。
3 4 11
S..D
....
....
终于发现某 一个小的剪枝错了。。。。。这个题杭电文档上搜索的例题,所以剪枝也 没有怀疑,自己实现的 时候搞错了。。。450ms+。。。慢死。。。
5Y。。。。居然是因为一个剪枝减导致第一次WA,然后又悲剧了3次,最后感觉自己的程序没啥问题啊,自己乱查 数据,自己想出了一组没有过。。。。
3 4 11
S..D
....
....
终于发现某 一个小的剪枝错了。。。。。这个题杭电文档上搜索的例题,所以剪枝也 没有怀疑,自己实现的 时候搞错了。。。450ms+。。。慢死。。。
#include <stdio.h> #include <string.h> char p[10][10]; int o[10][10],n,m,t,endr,endc,z; int a[4] = {0,0,1,-1}; int b[4] = {1,-1,0,0}; void dfs(int x,int y,int step) { int i; o[x][y] = 1; if(z) return ; if(step == t&&x == endr&&y == endc) { z = 1; return ; } else if(step > t) return ; for(i = 0;i <= 3;i ++) { if(x+a[i] >= 0&&y+b[i] >= 0&&x+a[i] <= n-1&&y+b[i] <= m-1) { if(o[x+a[i]][y+b[i]] == 0) { dfs(x+a[i],y+b[i],step+1); o[x+a[i]][y+b[i]] = 0; } } } o[x][y] = 0; return ; } int main() { int i,j,strr,strc,z1; while(scanf("%d%d%d%*c",&n,&m,&t)!=EOF) { z1 = z = 0; memset(o,0,sizeof(o)); if(!n&&!m&&!t) break; for(i = 0; i <= n-1; i ++) { for(j = 0; j <= m-1; j ++) { scanf("%c",&p[i][j]); if(p[i][j] == 'S') { strr = i; strc = j; } else if(p[i][j] == 'D') { endr = i; endc = j; } else if(p[i][j] == 'X') { o[i][j] = 1; } } getchar(); } if((strr+strc)%2 == (endr+endc)%2) { if(t%2) z1 = 0; else z1 = 1; } else { if(t%2) z1 = 1; else z1 = 0; } if(z1) dfs(strr,strc,0); else z = 0; if(z) printf("YES\n"); else printf("NO\n"); } return 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
- hdu1010 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
- 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 (DFS + 奇偶剪枝)
- 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(DFS+奇偶剪枝)
- HDU 1010 Tempter of the Bone