首页 > 其他 > 详细

迷宫问题

时间:2018-07-09 13:53:58      阅读:145      评论:0      收藏:0      [点我收藏+]
#include<bits/stdc++.h>
using namespace std;
int a,ans=0,c[105][105];
char b[105][105];

int p(int x,int y)
{
	if(x==1&&y==a)
	{
		ans++;
		return 1;
	}
	bool sf=0;
	if(b[x-1][y]==‘0‘&&!c[x-1][y]) c[x-1][y]=1,p(x-1,y),sf=1,c[x-1][y]=0;
	if(b[x-1][y+1]==‘0‘&&!c[x-1][y+1]) c[x-1][y+1]=1,p(x-1,y+1),sf=1,c[x-1][y+1]=0;
	if(b[x-1][y-1]==‘0‘&&!c[x-1][y-1]) c[x-1][y-1]=1,p(x-1,y-1),sf=1,c[x-1][y-1]=0;
	if(b[x][y+1]==‘0‘&&!c[x][y+1]) c[x][y+1]=1,p(x,y+1),sf=1,c[x][y+1]=0;
	if(b[x][y-1]==‘0‘&&!c[x][y-1]) c[x][y-1]=1,p(x,y-1),sf=1,c[x][y-1]=0;
	if(b[x+1][y]==‘0‘&&!c[x+1][y]) c[x+1][y]=1,p(x+1,y),sf=1,c[x+1][y]=0;
	if(b[x+1][y+1]==‘0‘&&!c[x+1][y+1]) c[x+1][y+1]=1,p(x+1,y+1),sf=1,c[x+1][y+1]=0;
	if(b[x+1][y-1]==‘0‘&&!c[x+1][y-1]) c[x+1][y-1]=1,p(x+1,y-1),sf=1,c[x+1][y-1]=0;
	
	return 0;
}

int main()
{
	cin>>a;
	c[1][1]=1;
	for(int i=1;i<=a;i++)
		for(int j=1;j<=a;j++) cin>>b[i][j];
	p(1,1);
	cout<<ans;
	return 0;
}

迷宫问题

原文:https://www.cnblogs.com/abs27/p/9283422.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!