| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Sequential Search
- Numpy
- 10953
- C++
- recursion
- Daily Commit
- 수 정렬하기
- Python
- markdown
- 2750
- centuryFromYear
- 백준
- matrixElementsSum
- cpp
- data_structure
- Counting cells in a blob
- flask
- almostIncreasingSequence
- til
- shapeArea
- 파이썬머신러닝완벽가이드
- baekjun
- 피보나치 수
- codesignal
- 파이썬 포렌식
- codesingal
- All Longest Strings
- adjacentElementsProduct
- collections.deque
- 2015 봄학기 알고리즘
Archives
- Today
- Total
Introfor
Recursion. 미로찾기 본문
#include <stdio.h>
int size = 8;
int maze[8][8] = {
{0, 0, 0, 0, 0, 0, 0, 1},
{0, 1, 1, 0, 1, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 0, 1},
{0, 1, 0, 0, 1, 1, 0, 0},
{0, 1, 1, 1, 0, 0, 1, 1},
{0, 1, 0, 0, 0, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 0, 1},
{0, 1, 1, 1, 0, 1, 0, 0},
};
int pathWay = 0;
int wall = 1;
int blocked = 2;
int path = 3;
int find_path(int x, int y){
if (x<0 || y<0 || x>=size || y>=size)
return 0;
else if (maze[x][y] != pathWay)
return 0;
else if (x==size-1 && y==size-1){
maze[0][0] = path;
return 1;
}
else{
maze[x][y] = path;
if (find_path(x+1, y) || find_path(x, y+1) || find_path(x-1, y) || find_path(x, y-1))
return 1;
maze[x][y] = blocked;
return 1;
}
}
int main(){
if (find_path(0,0))
printf("Found");
else
printf("Not Found");
return 0;
}
'Doing > C&C++' 카테고리의 다른 글
| Byte padding (0) | 2020.09.07 |
|---|---|
| [Recursion] Counting Cells in a Blob (0) | 2020.07.30 |
| [data_structure] Linked List (0) | 2020.07.26 |
| [Algorithm] sequential Search (0) | 2020.07.01 |
| [C++] Reference (0) | 2020.06.29 |
Comments