40分蒟蒻求助

P1605 迷宫

求助哪里错了
by 易安居士 @ 2019-10-31 21:47:37


@[上帝右手](/space/show?uid=192407) >在迷宫中移动有**上下左右**四种方式
by Alex_Wei @ 2019-10-31 21:50:29


@[Alex_Wei](/space/show?uid=123294) 但这里不是只能向下和右走吗
by 易安居士 @ 2019-10-31 21:57:07


@[上帝右手](/space/show?uid=192407) 这是题面
by Alex_Wei @ 2019-10-31 21:57:55


题目上没有说只能向下和向右走
by Alex_Wei @ 2019-10-31 21:58:12


哦哦,我去试试
by 易安居士 @ 2019-10-31 21:58:49


```cpp #include<bits/stdc++.h> using namespace std; int n,m,t,sx,sy,fx,fy,tu[10][10],ans,zx[4]={0,0,1,-1},zy[4]={1,-1,0,0}; void into() { cin>>n>>m>>t; cin>>sx>>sy>>fx>>fy; int lx,ly; for(register int i=1;i<=t;i++) { cin>>lx>>ly; tu[lx][ly]=1; } } void slove(int a,int b) { if(a>n||b>m||a<1||b<1) return; if(a==fx&&b==fy) { ans++; return; } //开始了 for(int i=1;i<=4;i++) { if(tu[a+zx[i]][b+zy[i]]==0) { tu[a][b]=1; slove(a+zx[i],b+zy[i]); } } } int main() { into(); slove(sx,sy); cout<<ans; return 0; } ```
by 易安居士 @ 2019-10-31 22:09:22


-@[Alex_Wei](/space/show?uid=123294) 爆了
by 易安居士 @ 2019-10-31 22:09:37


@[上帝右手](/space/show?uid=192407) 您应该判断一下边界 不然肯定会爆啊
by Alex_Wei @ 2019-10-31 22:13:14


@[Alex_Wei](/space/show?uid=123294) if(a>n||b>m||a<1||b<1) return;
by 易安居士 @ 2019-10-31 22:21:36


| 下一页