| #include <iostream> using namespace std; |
| int map[16][16]; |
| bool visit[16][16]; |
| bool chk; |
| int dx[4]={0,0,1,-1}; |
| int dy[4]={1,-1,0,0}; |
| void dfs(int y, int x) |
| { |
| for(int i=0; i<4; i++) |
| { |
| visit[y][x]=1; |
| int ny=y+dy[i]; |
| int nx=x+dx[i]; |
| if(map[ny][nx]==3) chk=1; |
| if(!visit[ny][nx] && !map[ny][nx]) |
| dfs(ny,nx); |
| visit[y][x]=0; |
| } |
| } |
| int main() |
| { |
| for(int T=1; T<=10; T++) |
| { |
| chk=0; |
| int tc; |
| cin >> tc; |
| for(int i=0; i<16; i++) |
| { |
| char input[16]; |
| cin >> input; |
| for(int j=0; j<16; j++) |
| map[i][j]=input[j]-'0'; |
| } |
| cout << "#" << T << " "; |
| dfs(1,1); |
| if(chk) cout << "1\n"; |
| else cout << "0\n"; |
| } |
| } |
'알고리즘 문제 풀이 > 1DP_과제(~180615)' 카테고리의 다른 글
| 171201_1316_그룹 단어 체커 (0) | 2017.12.01 |
|---|---|
| 171130_2864_5와 6의 차이 (0) | 2017.11.30 |
| 171128_1495_기타리스트 (0) | 2017.11.28 |
| 171128_1495_기타리스트 (큐 이용) (0) | 2017.11.28 |
| 171127_14891_톱니바퀴 (0) | 2017.11.27 |