1 solutions

  • 1
    @ 2022-3-24 21:26:55
    #include <stdio.h>
    #include <math.h>
    #include <algorithm>
    #include <iostream>
    #include <string.h>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <vector>
    using namespace std;
    int n,m,ans=0,vis[25][25],k;
    int dx[4]= {0,-1,0,1},dy[4]= {-1,0,1,0};
    char a[25][25];
    struct ti {
        int start;
        int en;
    };
    ti b[100];
    void dfs(int x,int y,int step) {
        step++;
        b[step].start=x+1;
        b[step].en=y+1;
        if(x==n-1&&y==n-1) {
            if(!k) {
                    cout<<"("<<1<<","<<1<<")";
                for(int i=2; i<=step; i++)
                    cout<<"->"<<"("<<b[i].start<<","<<b[i].en<<")";
                k=1;
            }
    
        }
        vis[x][y]=1;
        for(int i=0; i<4; i++) {
            int tx=x+dx[i],ty=y+dy[i];
            if(tx>=0&&ty>=0&&tx<n&&ty<n&&vis[tx][ty]==0&&a[tx][ty]=='0') {
                dfs(tx,ty,step);
            }
        }
    }
    int main() {
        scanf("%d",&n);
        for(int i=0; i<n; i++) {
            cin>>a[i];
        }
        dfs(0,0,0);
        return 0;
    }
    
    • 1

    Information

    ID
    768
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    8
    Tags
    # Submissions
    245
    Accepted
    47
    Uploaded By