diff --git "a/YooGyeongMo/DP/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" "b/YooGyeongMo/DP/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" new file mode 100644 index 0000000..5057d20 --- /dev/null +++ "b/YooGyeongMo/DP/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" @@ -0,0 +1,35 @@ +n = int(input()) +board = [list(map(int, input().split())) for _ in range(n)] + +# 상태: 가로(0), 세로(1), 대각선(2) +# dp[state][r][c] = 해당 위치에서 가능한 경로 수 +dp = [[[-1] * n for _ in range(n)] for _ in range(3)] + +def move_pipe(state, r, c): + # 끝에 도달하면 1 + if r == n - 1 and c == n - 1: + return 1 + + # 이미 계산된 경로라면 재사용 + if dp[state][r][c] != -1: + return dp[state][r][c] + + total = 0 + + # 가로 이동 + if state != 1 and c + 1 < n and board[r][c + 1] == 0: + total += move_pipe(0, r, c + 1) + + # 세로 이동 + if state != 0 and r + 1 < n and board[r + 1][c] == 0: + total += move_pipe(1, r + 1, c) + + # 대각선 이동 + if r + 1 < n and c + 1 < n: + if board[r][c + 1] == 0 and board[r + 1][c] == 0 and board[r + 1][c + 1] == 0: + total += move_pipe(2, r + 1, c + 1) + + dp[state][r][c] = total + return total + +print(move_pipe(0, 0, 1)) \ No newline at end of file diff --git a/YooGyeongMo/README.md b/YooGyeongMo/README.md index 5bca36d..df0ac49 100644 --- a/YooGyeongMo/README.md +++ b/YooGyeongMo/README.md @@ -3,4 +3,5 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2025.03.30 | 구현 | [유연 근무제](https://school.programmers.co.kr/learn/courses/30/lessons/388351?language=swift)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/5| ---- +| 2차시 | 2025.04.10 | DP | [파이프 옮기기 1](https://www.acmicpc.net/problem/17070)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/9| +--- \ No newline at end of file