P1605 迷宫

暴搜,回溯

const int N=10;
bool g[N][N];
int ans;
PII st,ed;
int n,m,k;

inline bool check(int x,int y)
{
    return x>=1 && x<=n && y>0 && y<=m;
}

void dfs(int x,int y)
{
    if(x == ed.fi && y == ed.se)
    {
        ans++;
        return;
    }

    for(int i=0;i<4;i++)
    {
        int a=x+dx[i],b=y+dy[i];
        if(check(a,b)&&!g[a][b])
        {
            g[a][b]=true;
            dfs(a,b);
            g[a][b]=false;
        }
    }
}

int main()
{
    cin>>n>>m>>k;
    cin>>st.fi>>st.se>>ed.fi>>ed.se;

    while(k--)
    {
        int x,y;
        cin>>x>>y;
        g[x][y]=true;
    }

    g[st.fi][st.se]=true;
    dfs(st.fi,st.se);

    cout<<ans<<endl;
    //system("pause");
}
posted @ 2020-09-17 20:31  Dazzling!  阅读(156)  评论(0编辑  收藏  举报