解题思路:一开始觉得是深搜模板题也没多想,结果WA,发现输入的出发点和终点都是先列再行(坑),改了下,又WA。起初的book数组我用来存结点是否走过,原来这里出bug了,题意是让我们找结点是否能在k次转弯内抵达。这里存在着可能这个结点上次搜超过k次了,但是我们把他标记走过,等到下次经过这却没超过k次,由于上次标记,我们也把他筛掉。这显然不正确,这是就改一下,book数组存到达本点的最小转弯数,就可以了。这种思路可以拓展到广搜,用优先队列,明天写下。
AC代码如下:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<stdlib.h>
#include<math.h>
#define inf 0x3f3f3f3f
using namespace std;
char image[110][110];
int book[110][110],nex[4][2]={0,1,1,0,0,-1,-1,0},n,m,k,flag,tx,ty;
bool judge(int x,int y)
{
if(x<1 || x>n || y<1 || y>m || image[x][y]=='*')
return true;
return false;
}
void dfs(int x,int y,int bearing)
{
if(x==tx && y