老鼠走迷宫问题怎么输出多种方法?
#include<stdio.h>
int s[7][7] = {{1, 1,1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 1},
{1, 0, 0, 1, 0, 1, 1},
{1, 1, 0, 1, 0, 1, 1},
{1, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1}
};
int l=0,p=0;
int w(int n,int m)
{
int i;
s[n][m]=2;
if(n==5&&m==5)
{
for(n=0;n<=6;n++)
{
for(m=0;m<=6;m++)
{
printf("%d ",s[n][m]);
}
printf("\n");
p++;
}
}
else
{
if(s[n][m+1]==0)
w(n,m+1);
if(s[n+1][m]==0)
w(n+1,m);
if(s[n][m-1]==0)
w(n,m-1);
if(s[n-1][m]==0)
w(n-1,m);
s[n][m] =0 ;
}
}
int main()
{
int x=1,y=1;
w(x,y);
if(p==0)
printf("no door");
return 0;
}