样例输入:
1
1
2 0
2 1 2
3 3 3 3
4 4 4 4 4
5 5 5 5 5 5
样例输出:
3
数据范围:
对于50%的数据,保证十步及以内有解;
对于70%的数据,保证没有太难了的情况;
对于70%的数据,T≤10;
数据有梯度。
题目分析:
这道题很明显是一道搜索题,A*剪枝就可以了。加一个迭代加深也是没有问题的。下附代码的A*剪枝用的是dfs,但实际上bfs时间才是更优的,但是因为bfs相对难写需要记录状态且空间上有可能会爆(不太确定)。
附代码:
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstring>
#include<string>
#include<cctype>
#include<iomanip>
#include<algorithm>
using namespace std;
const int fx[5]={
0,-1,-1