hdu 1010 Tempter of the Bone(DFS奇偶性剪枝+多重剪枝)
来源:互联网 发布:卡五星麻将app源码 编辑:程序博客网 时间:2024/06/07 17:07
题目链接:hdu1010
本题重点考察:剪枝,奇偶性剪枝
#include<stdio.h>#include<stdlib.h>#include<iostream>using namespace std;char map[8][8];int stx,sty,endx,endy,n,m,t,yes;//stx,sty表示出发点,yes判断是否符合条件int f[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};void dfs(int x,int y,int ans){ if(ans == t)//剪枝,如果到了t时间能到达结束点,yes = 1;否则,直接返回 { if(x == endx && y == endy) yes = 1; return ; } if(yes) return ;//已找到解后,结束其它还在进行的搜索 int temp = abs(x - endx) + abs(y - endy) - abs(ans - t); if(temp % 2 || temp > 0) return ;//重点,奇偶性剪枝 for(int i = 0 ; i < 4 ; i ++) { int fx = x + f[i][0]; int fy = y + f[i][1]; if(fx >= 0 && fx < n && fy >= 0 && fy < m && map[fx][fy] != 'X') { map[fx][fy] = 'X'; dfs(fx,fy,ans + 1); map[fx][fy] = '.'; } }}int main(){ //freopen("in.txt","r",stdin); int i,j; while(scanf("%d%d%d",&n,&m,&t) && (n + m + t)) { int wall = 0; for(i = 0 ; i < n ; i ++) { scanf("%s",map[i]); for(j = 0 ; j < m ; j ++) { if(map[i][j] == 'X') wall ++; else if(map[i][j] == 'S') { stx = i; sty = j; } else if(map[i][j] == 'D') { endx = i; endy = j; } } } if(n * m - wall <= t) printf("NO\n");//剪枝,如果能走的格子比时间少,不符合条件 else { yes = 0; map[stx][sty] = 'X'; dfs(stx,sty,0); if(yes) printf("YES\n"); else printf("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 1011 Tempter of the Bone【DFS+奇偶性剪枝】
- HDOj 1010 Tempter of the Bone(DFS+奇偶性剪枝)
- HDU 1010 Tempter of the Bone(DP+奇偶性剪枝)
- 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 + 奇偶剪枝)
- 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+奇偶剪枝)
- linux 下 avr开发环境的搭建
- Myeclipse中导入Android项目时,提示的错误:unable to resolve target 'android-14'
- 消除下载Android源码时的“curl: (7)”等错误
- UBUNTU添加开机自动启动程序方法
- org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not
- hdu 1010 Tempter of the Bone(DFS奇偶性剪枝+多重剪枝)
- MindNode.app 思维导图 下载是Pro版哦
- org.hibernate.exception.GenericJDBCException: Cannot open connection
- A+B Problem新解
- C++文件流_矩阵相乘
- shell脚本学习-为什么使用 shell 编程
- scrollTo、scrollBy、getScrollX、getScrollY这4个方法的含义
- thunderbird邮箱备份方法
- Ural 1091. Tmutarakan Exams 排列组合+容斥原理+质因数分解