为啥50pts呢?!

P1238 走迷宫

```c++ #include<bits/stdc++.h> using namespace std; int n,m,t,cnt,ans; int sx,sy,fx,fy,k; int mat[100][100]; int book[100][100]; int nxt[4][2]={0,-1,-1,0,0,1,1,0}; struct xy{ int x,y; }a[500]; void dfs(int x,int y){ if(x==fx&&y==fy){ ans++; cout<<"("<<sx<<","<<sy<<")->"; for(int i=1;i<=k-1;i++) cout<<"("<<a[i].x<<","<<a[i].y<<")->"; cout<<"("<<fx<<","<<fy<<")"<<endl; return ; } for(int i=0;i<4;i++){ int nx=x+nxt[i][0]; int ny=y+nxt[i][1]; if(nx>=1&&ny>=1&&nx<=m&&ny<=n&&mat[nx][ny]==1&&book[nx][ny]==0){ book[x][y]=1; a[k].x=x; a[k].y=y; k++; dfs(nx,ny); k--; book[x][y]=0; } } } int main(){ cin>>m>>n; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ cin>>mat[i][j]; } } cin>>sx>>sy>>fx>>fy; dfs(sx,sy); if(ans==0) cout<<"-1"; return 0; } ``` 思路应该差不多,对照一下吧\ 求关注
by zhouyk0501 @ 2023-10-11 20:03:15


看上去一样啊?只不过我把k变成了dfs参数而已,样例是能过的,这是我[提交记录](https://www.luogu.com.cn/record/128770789),我还下载了#11的数据,发现莫名其妙的只输出-1,我也不知道为啥,dalao,既然你都发了代码了,能帮我查一查吗p_q
by MC_OIer @ 2023-10-11 21:35:46


sorry,看到了,dfs起点的问题,我简直是……
by MC_OIer @ 2023-10-11 22:41:16


|