WA求改,蒟蒻不会,dfs做的,感觉没啥问题啊
查看原帖
WA求改,蒟蒻不会,dfs做的,感觉没啥问题啊
1187198
davidea楼主2025/8/4 22:41
#include <bits/stdc++.h>
using namespace std;

int maps[4][8];
int dx[4]={1,0,0,1};
int dy[4]={0,1,0,1};
int bx,by,ans,x,y;
void work(long long x,long long y){
    maps[x][y]=1;
    maps[x-1][y-2]=1;
    maps[x-2][y-1]=1;
    maps[x-2][y+1]=1;
    maps[x-1][y+2]=1;
    maps[x+1][y-2]=1;
    maps[x+2][y-1]=1;
    maps[x+2][y+1]=1;
    maps[x+1][y+2]=1;
}
void dfs(int x1,int y1,int step){
    if(x1==bx && y1==by){
        ++ans;
        return ;
    }
    for(int i=0;i<4;i++){
        int nx=x1+dx[i];
        int ny=y1+dy[i];
        if(nx>=0 && nx<4 && ny>=0 && ny<8 && maps[nx][ny]==0){
            maps[nx][ny]=1;
            dfs(nx,ny,step+1);
            maps[nx][ny]=0;
        }
    }
}

int main(){
    cin>>bx>>by>>x>>y;
    work(x,y);
    dfs(0,0,5);
    cout<<ans<<endl;
}

2025/8/4 22:41
加载中...