-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1129.cpp
More file actions
44 lines (41 loc) · 989 Bytes
/
P1129.cpp
File metadata and controls
44 lines (41 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int a[100][100];
int tmd[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
pair<int , int> ans[1000];
int vit[100][100];
void dfs(int x,int y,int cnt){
ans[cnt]={x,y};
if(x==n&&y==m){
return;
}
for(int i=0;i<4;i++){
int tx = x+tmd[i][0],ty = y + tmd[i][1];
if(tx>n||tx<1||ty>m||ty<1) continue;
if(vit[tx][ty]) continue;
if(a[tx][ty]==1){
vit[tx][ty]=1;
dfs(tx,ty,cnt+1);
vit[tx][ty]=0;
}
}
}
signed main(){
while(cin>>n>>m){
memset(vit,0,sizeof vit);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
vit[1][1]=1;
dfs(1,1,0);
for(int i=0;i<n+m-2;i++){
cout<<"("<<ans[i].first<<","<<ans[i].second<<")>";
}
cout<<"("<<ans[n+m-2].first<<","<<ans[n+m-2].second<<")\n";
}
return 0;
}