3 条题解

  • 1
    @ 2025-10-18 19:39:31

    #include<bits/stdc++.h> #define ll long long using namespace std; int n,a[10][10],ans; void dfs(int x,int y){ a[x][y]=2; if(x1&&yn){ a[x][y]=1; ans++; return ; } if(a[x+1][y]==1){ a[x+1][y]=2; dfs(x+1,y); a[x+1][y]=1; } if(a[x-1][y]==1){ a[x-1][y]=2; dfs(x-1,y); a[x-1][y]=1; } if(a[x][y+1]==1){ a[x][y+1]=2; dfs(x,y+1); a[x][y+1]=1; } if(a[x][y-1]==1){ a[x][y-1]=2; dfs(x,y-1); a[x][y-1]=1; } if(a[x-1][y-1]==1){ a[x-1][y-1]=2; dfs(x-1,y-1); a[x-1][y-1]=1; } if(a[x+1][y+1]==1){ a[x+1][y+1]=2; dfs(x+1,y+1); a[x+1][y+1]=1; } if(a[x+1][y-1]==1){ a[x+1][y-1]=2; dfs(x+1,y-1); a[x+1][y-1]=1; } if(a[x-1][y+1]==1){ a[x-1][y+1]=2; dfs(x-1,y+1); a[x-1][y+1]=1; } } int main(){ cin>>n; for(int i=1;i<=n;i++)for(int j=1;j<=n;++j)cin>>a[i][j]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)++a[i][j]; } dfs(1,1); cout<<ans; return 0;

          1. }````



    col1**** col2 col3
    • 1
      @ 2022-7-29 20:10:20
      #include<bits/stdc++.h>
      using namespace std;
      long i,j,n,s,a[105][105],dx[9]={-1,1,0,0,-1,-1,1,1},dy[9]={0,0,-1,1,-1,1,-1,1},b[105][105];
      void dfs(long x,long y)//深搜
      {
      	long i,x1,y1;
      	for(i=0;i<8;i++)
      	{
      		x1=x+dx[i];
      		y1=y+dy[i];
      		if(x1>0&&x1<=n&&y1>0&&y1<=n&&!a[x1][y1]&&!b[x1][y1])
      		{
      			b[x1][y1]=1;
      			if(x1==1&&y1==n)s++;
      			else dfs(x1,y1);
      			b[x1][y1]=0;
      		}
      	}
      }
      int main()
      {
      	cin>>n;
      	for(i=1;i<=n;i++)
      		for(j=1;j<=n;j++)cin>>a[i][j];
      	b[1][1]=1;
      	dfs(1,1);
      	cout<<s;
      	return 0;
      }
      • 1
        @ 2022-7-15 9:18:48

        大法师

        #include <bits/stdc++.h>
        using namespace std;
        const int N = 205, dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
        int n, ans;
        bool vis[N][N];
        void dfs(int x, int y) {
        	if (x > n || x < 1 || y > n || y < 1 || vis[x][y]) return;
        	if (x == 1 && y == n) return (void)(ans ++);
        	vis[x][y] = true;
        	for (int i = 0; i < 8; i ++)
        		dfs(x + dx[i], y + dy[i]);
        	vis[x][y] = false;
        }
        int main() {
        	cin >> n;
        	for (int i = 1; i <= n; i ++)
        		for (int j = 1; j <= n; j ++)
        			cin >> vis[i][j];
        	dfs(1, 1);
        	cout << ans << '\n';
        	return 0;
        }
        
        • 1

        信息

        ID
        141
        时间
        1000ms
        内存
        256MiB
        难度
        5
        标签
        (无)
        递交数
        152
        已通过
        55
        上传者