2 条题解

  • 2
    @ 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;
    }
    • 2
      @ 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
      标签
      (无)
      递交数
      147
      已通过
      53
      上传者