*문제 출처는 백준에 있습니다.
문제 제목: 컴백홈 / 1189번 (실버 1단계)
문제 사이트: https://www.acmicpc.net/problem/1189
문제 설명

나의 풀이
# 결과 값
answer = 0
# 상 하 좌 우 움직임
move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
def solution(load, visited, count ,iy, ix, r, c, k):
global answer
# 무한 반복을 종료한다.
if count > k:
return
if iy == 0 and ix == c - 1 and count == k:
answer += 1
return
for ny, nx in move:
y = ny + iy
x = nx + ix
if 0 <= y < r and 0 <= x < c and not visited[y][x] and load[y][x] == '.':
visited[y][x] = True
solution(load, visited, count + 1, y, x, r, c, k)
visited[y][x] = False
def main():
# 정답
global answer
r, c, k = map(int, input().split())
# 길
load = [list(input()) for _ in range(r)]
# 방문 처리
visited = [[False] * c for _ in range(r)]
visited[r - 1][0] = True
solution(load, visited, 1, r - 1, 0, r, c, k)
print(answer)
if __name__=="__main__":
main()

※ 알아야 할 것
'Coding Test > 백준-Python' 카테고리의 다른 글
| 백준 / N과 M (11) / 15665번 / Python (0) | 2025.05.23 |
|---|---|
| 백준 / 차이를 최대로 / 10819번 / Python (0) | 2025.05.22 |
| 백준 / 색종이 / 2563번 / Python (0) | 2025.05.18 |
| 백준 / 경쟁적 전염 / 18405번 / Python (0) | 2025.05.16 |
| 백준 / 사다리 조작 / 15684번 / Python (0) | 2025.05.15 |