3 条题解

  • 0
    @ 2023-4-6 19:05:45
    #include<bits/stdc++.h>
    using namespace std;
    int a[10001][10001];
    int book[10001][10001],next[8][2]= {{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}},n,sum=0;
    void dfs(int x,int y) {
    	if(x==1 && y==n) {
    		sum++;
    		return;
    	}
    	for(int k=0; k<8; k++) {
    		int tx=x+next[k][0];
    		int ty=y+next[k][1];
    		if(tx<1 || tx>n || ty<1 || ty>n)	continue;
    		if(a[tx][ty]==0 && book[tx][ty]==0) {
    			book[tx][ty]=1;
    			dfs(tx,ty);
    			book[tx][ty]=0;
    		}
    	}
    	return;
    }
    int main() {
    	cin>>n;
    	for(int i=1; i<=n; i++) {
    		for(int j=1; j<=n; j++) {
    			cin>>a[i][j];
    		}
    	}
    	book[1][1]=1;
    	dfs(1,1);
    	cout<<sum;
    	return 0;
    }
    

    信息

    ID
    1110
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    递交数
    114
    已通过
    34
    上传者