翟大侠第一次发题解

翟翟  •  9个月前


include<bits/stdc++.h>

using namespace std; struct point {

int x,y,z;

}c[10][10]; int cx[8]={-1,-1,-1, 0,0,1, 1,1}; int cy[8]={-1,0, 1, -1,1,-1,0,1}; int n,ans = 0; void dfs(int x,int y){

if (x==0&&y==n-1){
	ans++;
	return ;
}
for (int i = 0;i<8;i++)
{
	int dx=x+cx[i],dy=y+cy[i];
	if (dx>=0&&dy>=0&&dx<n&&dy<n&&c[dx][dy].z==0)
	{
		c[dx][dy].z=1;
		dfs(dx,dy);
		c[dx][dy].z=0;
	}
}

} int main() {

cin>>n;
for (int i = 0;i<n;i++){
	for (int j = 0;j<n;j++){
		a[i][j]=1;
	}
}
for (int i = 0;i<n;i++){
	for (int j = 0;j<n;j++){
		int tmp;
		cin>>tmp;
		c[i][j].x=i;
		c[i][j].y=j;
		c[i][j].z=tmp;
	}
}
c[0][0].z=1;
dfs(0,0);
cout<<ans;
return 0;

}


评论:

请先登录,才能进行评论