大佬帮修修傻*dfs代码
查看原帖
大佬帮修修傻*dfs代码
914266
Narycap楼主2024/7/29 17:42

各位大佬帮忙看看,本入门蒟蒻写的dfs代码第20~23行VSCode提示出现异常,为此已经整了一下午了(呜呜) (也就我这个天才能想到用dfs写dp的题)

#include<bits/stdc++.h>
#define int long long
#pragma GCC optimiza(3)
using namespace std;

const int fx[9] = {0, -2, -1, 1, 2, 2, 1, -1, -2};
const int fy[9] = {0, 1, 2, 2, 1, -1, -2, -2, -1};
int qp[25][25];
int roads,ox=0,oy=0,lx,ly,hx,hy;

void dfs(int lx,int ly)
{
    if(ox==lx && oy==ly)
    {
        roads++;
        return ;
    }
    while(qp[ox][oy]==0)
    {
        dfs(ox++,oy);
        dfs(ox--,oy);
        dfs(ox,oy++);
        dfs(ox,oy--);
    }
}

signed main()
{
    freopen("P1002.in","r",stdin);
    freopen("P1002.out","w",stdout);
    cin>>lx>>ly>>hx>>hy;
    for(int i=0;i<=ly;i++)
    {
        for(int j=0;j<=lx;j++)
        {
            qp[i][j]=0;
        }
    }
    qp[hy][hx]=1;
    for(int i=1;i<=8;i++)
    {
        qp[hy+fy[i]][hx+fx[i]]=1;
    }
    dfs(lx,ly);
    cout<<roads<<endl;
    // for(int i=0;i<=ly;i++)
    // {
    //     for(int j=0;j<=lx;j++)
    //     {
    //         cout<<qp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    system("pause");
    return 0;
}


2024/7/29 17:42
加载中...