The endpoint must be x to complete, if it is ". "Means two times to the end.
Use mat[i][j] to indicate the number of times that the point can pass
#include "Cstdio" #include "CString" #include "queue" #include "iostream" #define MAXN 505using namespace Std;int dx[4]={- 1,1,0,0};int dy[4]={0,0,-1,1};int mat[maxn][maxn];int x,y,ok,mark;char arr[maxn];struct point{int x; int y;} S,e,temp;bool DFS (point s) {//cout<<s.x<< ' \ t ' <<s.y<<endl; if (S.x==e.x&&s.y==e.y&&!mat[s.x][s.y]) {Ok=1;return true;} if (OK) return true; for (int k=0;k<4;k++) {temp.x=s.x+dx[k]; TEMP.Y=S.Y+DY[K]; cout<<mat[temp.x][temp.y]<< ' \ t ' <<endl; if (Temp.x>=0&&temp.x<x&&temp.y>=0&&temp.y<y&&mat[temp.x][temp.y]) { mat[temp.x][temp.y]--; if (Dfs (temp)) return true; }} return false;} int main () {while (scanf ("%d%d", &x,&y)!=eof) {memset (mat,0,sizeof (MAT)); for (int i=0;i<x;i++) {scanf ("%s", arr); for (int j=0;j<y;j++) {if (arr[j]== '. ') Mat[i][J]=1; else mat[i][j]=0; }} scanf ("%d%d", &s.x,&s.y); s.x--;s.y--; scanf ("%d%d", &e.x,&e.y); e.x--;e.y--; ok=0; mark=1; Mat[s.x][s.y]=1; mat[e.x][e.y]++; DFS (s); if (OK) printf ("yes\n"); else printf ("no\n"); } return 0;}
Codeforce 540C: (DFS)