暴力DFS 0分求调!!!悬棺
查看原帖
暴力DFS 0分求调!!!悬棺
1323415
wky_wsy楼主2024/11/19 22:17

WA on #1#2#5,TLE on #2#3。

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
int cnt=0;
int n,m,xb,yb;
int a[30][30];
void dfs(int x,int y){
    if(x==n&&y==m) ++cnt;
    if(x<=n&&x>=0&&y<=n&&y>=0&&a[x][y]==0){
        dfs(x+1,y);
        dfs(x,y+1);
    }
}
signed main(){
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>xb>>yb;
    if(xb-2>=0&&yb-1>=0) a[xb-2][yb-1]=1;
    if(xb-2>=0&&yb+1<=m) a[xb-2][yb+1]=1;
    if(yb+2<=m&&xb-1>=0) a[xb-1][yb+2]=1;
    if(yb+2<=m&&xb+1<=n) a[xb+1][yb+2]=1;
    if(xb+2<=n&&yb+1<=m) a[xb+2][yb+1]=1;
    if(xb+2<=n&&yb-1>=0) a[xb+2][yb-1]=1;
    if(yb-2>=0&&xb-1>=0) a[xb-1][yb-2]=1;
    if(yb-2>=0&&xb+1<=n) a[xb+1][yb-2]=1;
    dfs(0,0);
    cout<<cnt;
}
2024/11/19 22:17
加载中...