码迷,mamicode.com
首页 > 其他好文 > 详细

迷宫问题

时间:2018-07-09 14:14:36      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:out   property   int   ring   ati   c++   amp   its   direct   

#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;
}

迷宫问题

标签:out   property   int   ring   ati   c++   amp   its   direct   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!