http://acm.hdu.edu.cn/showproblem.php?pid=1010
/*
if calculate the minimum step by BFS,it will get TLE ,too.
学习了新东西,先奇偶性判断
迷宫看成0 1交错的格子,从0到1要奇数步,0到0要偶数步。体会剪枝的重要性
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
char maze[8][8];
int vis[8][8],m,n,t;
int next[4][2]={0,1,0,-1,1,0,-1,0};
bool ok(int x,int y)
{
if(x<0||x>=m||y<0||y>=n||maze[x][y]=='X')
return 0;
return 1;
}
int flag;
void dfs(int x,int y,int st)
{
if(flag)
return ;
if(st>t)
return ;
if(st==t)
{
if(maze[x][y]=='D')
本文详细探讨了如何使用深度优先搜索(DFS)策略,并结合剪枝技术解决HDU 1010编程挑战。通过实例解析,解释了在求解过程中如何有效地避免无效状态,提高算法效率。
订阅专栏 解锁全文
4228

被折叠的 条评论
为什么被折叠?



