hdu 1010 Tempter of the Bone_奇偶剪枝+dfs
来源:互联网 发布:matlab迭代解方程算法 编辑:程序博客网 时间:2024/05/16 15:13
题目链接: ~click here ~
奇偶剪枝解释:~click here~
#include <cstdio>#include <cstring>#include <iostream>#include <stdlib.h>using namespace std;char map[9][9];int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};int n,m,t,sum;int sx,sy,ddx,ddy;bool dfs(int x,int y,int time){ int px,py; if(x==ddx && y==ddy && time==t) { return true;//正确 } else { if(abs(ddx-x)+abs(ddy-y)>t-time)return false; for(int i=0;i<4;i++) { px=x+dx[i]; py=y+dy[i]; if(map[px][py]!='X' && time+1<=t) { map[px][py]='X'; if(dfs(px,py,time+1))return true; map[px][py]='.'; } } } return false;}int main(){ while(scanf("%d%d%d",&n,&m,&t),n || m || t) { memset(map,'X',sizeof(map)); sum=0; getchar(); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%c",&map[i][j]); if(map[i][j]=='S') { sx=i; sy=j; } if(map[i][j]=='D') { ddx=i; ddy=j; } if(map[i][j]=='.')sum++; } getchar(); } if(sum+1<t || (t+sx+sy+ddx+ddy)%2==1)printf("NO\n"); //奇偶性判别与可达性判别 else { map[sx][sy]='X'; if(dfs(sx,sy,0))printf("YES\n"); else printf("NO\n"); } } return 0;}
0 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 1010Tempter 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+奇偶剪枝)
- hdu 1010 Tempter of the Bone题解(dfs+奇偶剪枝)
- Python名词单数变换为复数函数
- Java之智力题【史上最全】
- 关于C++中的虚函数
- 去除android手机信号图标
- JavaScript中双叹号(!!)作用
- hdu 1010 Tempter of the Bone_奇偶剪枝+dfs
- 时间类---友元
- linux下进程间通信的几种主要手段简介
- 23种设计模式(14):解释器模式
- android activity之间跳转 setResult 和 StartActivityForResult
- iOS-Bug: NSRunloop Mode
- 人在做,天在看!人生不可破的28条天规
- 合并 apk和 odex 文件到一个apk中
- Set Matrix Zeroes