有没有佬能给我指点一下(用的是搜索)
查看原帖
有没有佬能给我指点一下(用的是搜索)
1461843
faithz楼主2025/1/9 20:53
#include <bits/stdc++.h>
using namespace std;
bool st[25][25];
int lx,ly,mx,my;
int dx[2] = {0,1},dy[2] = {1,0}; 
int dfs(int x,int y)
{
    int res = 0;
    if(x == lx && y == ly)res ++;

    
    for(int i = 0;i < 2;i++)
    {
        int x1 = x + dx[i],y1 = y + dy[i];
        if(x1 <= lx && y1 <= ly && !st[x1][y1])dfs(x1,y1);
    }
    return res;
}
int main()
{
    
    cin >> lx >> ly >> mx >> my;

    st[mx - 1][my - 2] = true;
    st[mx + 1][my - 2] = true;
    st[mx - 2][my + 1] = true;
    st[mx + 2][my + 1] = true;
    st[mx - 2][my - 1] = true;
    st[mx + 2][my - 1] = true;
    st[mx - 1][my + 2] = true;
    st[mx + 1][my + 2] = true;

    cout << dfs(0,0);
    return 0;
}
2025/1/9 20:53
加载中...