HDOJ 1010解题 : http://acm.hdu.edu.cn/showproblem.php?pid=1010
在回顾搜索算法,DFS、BFS、回溯等。以HDOJ 1010题练习,虽然题目非常简单,但还是花了较长时间才AC。一开始没有剪枝,果断超时。进行了奇偶剪枝后ac。
//奇偶剪枝:如果起点横纵坐标和与终点坐标和奇偶性不同,则说明要走奇数步,如果要求走t步,
//t为偶数,则肯定不可能有答案;反之亦然。
#include <iostream>
#include <cstdlib>
using namespace std;
int n,m,t;
char map[8][8];
int visited[8][8];
int stepx[] = {-1, 0, 1, 0};
int stepy[] = {0, 1, 0, -1};
int start[2];
int end[2];
int depth;
int escape;
void DFS(int x, int y, int time)
{
if(x<=0 || x>n || y<=0 || y>m)//防止越界
{
return;
}
visited[x][y]=1;
depth++;
if(map[x][y]=='D' &&