1 solutions

  • 0
    @ 2022-3-24 20:15:15
    #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[15][15],k;
    int dx[4]= {0,1,0,-1},dy[4]= {1,0,-1,0};
    char a[15][15];
    struct ti {
        int start;
        int en;
    };
    ti b[100];
    void dfs(int x,int y,int step) {
        step++;
        b[step].start=x;
        b[step].en=y;
        if(x==n&&y==m) {
            k=1;
            ans++;
            cout<<ans<<":";
            cout<<1<<","<<1;
            for(int i=2; i<=step; i++)
                cout<<"->"<<b[i].start<<","<<b[i].en;
            cout<<endl;
        }
    
        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<=m&&vis[tx][ty]==0&&a[tx][ty]=='o') {
                dfs(tx,ty,step);
            }
        }
        vis[x][y]=0;
    }
    int main() {
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {
                cin>>a[i][j];
            }
        }
        dfs(1,1,0);
        if(!k)
            cout<<"no"<<endl;
        return 0;
    }
    

    Information

    ID
    748
    Time
    1000ms
    Memory
    64MiB
    Difficulty
    6
    Tags
    # Submissions
    98
    Accepted
    33
    Uploaded By