#以下代码 在蓝桥杯dfs 迷宫的题目中 提交是正确的
但是 在dev测试的时候 却一直输出99999
谁能帮我看一下问题在哪
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<malloc.h>
typedef struct Node {
int x;//位置信息
int y;
int pre;//前一个结点下标
char aa;//当前结点的下一步走法L/R/D/U
} node;
node nodes[1500];
int mg[30][50]; //迷宫
int f[30][50]= {0}; //辅助数组,记录已经访问结点
int pos[4][2]= {{1,0},{0,-1},{0,1},{-1,0}}; //上下左右
char sol[1500];
int s=0;
void print(int head) {
while(nodes[head].pre!=-1) {
sol[s++]=nodes[head].aa;
print(nodes[head].pre);
break;
}
}
void bfs(int x,int y) {
int head=0,tail=1;
int i;
nodes[0].x=x;
nodes[0].y=y;
nodes[0].pre=-1;
struct Node next;
while(head<tail) {
if(nodes[head].x==29&&nodes[head].y==49) {
print(head);
}
for(i=0; i<4; i++) {
next.x=nodes[head].x+pos[i][0];
next.y=nodes[head].y+pos[i][1];
next.pre=head;
if(next.x<30&&next.x>-1&&next.y<50&&next.y>-1) {
if(mg[next.x][next.y]!=1&&f[next.x][next.y]!=1) {
f[next.x][next.y]=1;
if(i==0) next.aa='D';
if(i==1) next.aa='L';
if(i==2) next.aa='R';
if(i==3) next.aa='U';
nodes[tail]=next;
tail++;
}
}
}
head++;
}
}
int main() {
int i,j;
for(i=0; i<30; i++) {
for(j=0; j<50; j++) {
scanf("%1d",&mg[i][j]);
}
}
bfs(0,0);
int len=strlen(sol);
for(i=0; i<len; i++) {
printf("%c\n",sol[i]);
}
}