5 条题解

  • 2
    @ 2025-7-18 11:38:30
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    const int N=1e2+10;
    int n,a[N][N],ans;
    int dx[]={-1,-1,-1, 0, 0, 1, 1, 1};
    int dy[]={-1, 0, 1,-1, 1,-1, 0, 1};
    bool check(int x,int y){
    	if(x>=1&&x<=n&&y>=1&&y<=n&&a[x][y]==0){
    		return 1;
    	}
    	return 0;
    }
    void dfs(int x,int y){
    	if(x==1&&y==n){
    		ans++;
    		return;
    	}
    	a[x][y]=1;
    	for(int i=0;i<=7;i++){
    		int xx=x+dx[i];
    		int yy=y+dy[i];
    		if(check(xx,yy)){
    			dfs(xx,yy);
    			a[xx][yy]=0;
    		}
    	}
    }
    signed main(){
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		for(int j=1;j<=n;j++){
    			cin>>a[i][j];
    		}
    	}
    	dfs(1,1);
    	cout<<ans;
    	return 0;
    }
    
    
    

    信息

    ID
    1296
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    382
    已通过
    129
    上传者