越来越不想写博客了。。。。但适当总结是很必要的。 1.深搜和广搜当有多组样例时,注意全局变量的清0和更新,还有数组和标记数组都要清0!! 2.数组标记用了不会错,不用可能超时,尽量都用。 3.一种通过递归记录路径的方法真实太妙了!!虽然我用的广搜的模板,但这个记录路径的方法有深搜的影子,很妙。 https://www.luogu.com.cn/problem/P6207
#include
using namespace std;
struct node
{
int x,y,s;
};
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int r,c,vis[200][200],dist[200][200][2],k;
char a[200][200];
queueq;
void bfs()
{
vis[1][1]=1;
node cur,nxt;
cur.x=1;cur.y=1;cur.s=0;
q.push(cur);
while(!q.empty())
{
cur=q.front();q.pop();
if(cur.x==r&&cur.y==c)
return ;
for(int i=0;i=1&&nxt.x=1&&nxt.yb>>c>>d>>k;
for(int i=a;i
关注
打赏