From dc25d5a000b4203ce47635ff12b8e10d1cbef851 Mon Sep 17 00:00:00 2001 From: "G.M_YOO" Date: Thu, 10 Apr 2025 22:03:54 +0900 Subject: [PATCH 1/3] =?UTF-8?q?2025-04-10=20=ED=8C=8C=EC=9D=B4=ED=94=84=20?= =?UTF-8?q?=EC=98=AE=EA=B8=B0=EA=B8=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: 파이프 옮기기 1 문제 풀이 추가 - python 언어 사용 이번에만. --- ...4 \354\230\256\352\270\260\352\270\260.py" | 29 +++++++++++++++++++ YooGyeongMo/README.md | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 "YooGyeongMo/DFS:BFS/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" diff --git "a/YooGyeongMo/DFS:BFS/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" "b/YooGyeongMo/DFS:BFS/\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..3ead0cd --- /dev/null +++ "b/YooGyeongMo/DFS:BFS/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" @@ -0,0 +1,29 @@ +n = int(input()) + +board = [] + +for _ in range(n): + board.append(list(map(int,input().split()))) + +answer = 0 + +def move_pipe(state,r,c): + global answer + + if r == n-1 and c == n-1: + answer+=1 + return + + can_move_h = c + 1 < n and board[r][c+1] == 0 + can_move_v = r + 1 < n and board[r+1][c] == 0 + + if state != 1 and can_move_h: + move_pipe(0, r, c + 1) + if state != 0 and can_move_v: + move_pipe(1, r+1, c) + if c + 1 < n and r + 1 < n : + if board[r][c+1] == 0 and board[r+1][c] == 0 and board[r+1][c+1] == 0: + move_pipe(2, r + 1, c + 1) + +move_pipe(0,0,1) +print(answer) \ No newline at end of file diff --git a/YooGyeongMo/README.md b/YooGyeongMo/README.md index 5bca36d..17e99e6 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 | dfs/bfs | [파이프 옮기기 1](https://www.acmicpc.net/problem/17070)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/9| +--- \ No newline at end of file From 4d9977f60a69cad2ab521f845084dfb0d4730c4b Mon Sep 17 00:00:00 2001 From: "G.M_YOO" Date: Thu, 10 Apr 2025 22:38:55 +0900 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=EC=95=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=A6=98=20=ED=8F=B4=EB=8D=94=20=EC=A2=85=EB=A5=98=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" | 0 YooGyeongMo/README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename "YooGyeongMo/DFS:BFS/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" => "YooGyeongMo/DP/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" (100%) diff --git "a/YooGyeongMo/DFS:BFS/\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" similarity index 100% rename from "YooGyeongMo/DFS:BFS/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" rename to "YooGyeongMo/DP/\355\214\214\354\235\264\355\224\204 \354\230\256\352\270\260\352\270\260.py" diff --git a/YooGyeongMo/README.md b/YooGyeongMo/README.md index 17e99e6..df0ac49 100644 --- a/YooGyeongMo/README.md +++ b/YooGyeongMo/README.md @@ -3,5 +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 | dfs/bfs | [파이프 옮기기 1](https://www.acmicpc.net/problem/17070)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/9| +| 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 From 7fc0fe3c4bb51b4dcaa20c10832fd7011c9fd105 Mon Sep 17 00:00:00 2001 From: "G.M_YOO" Date: Wed, 16 Apr 2025 02:39:57 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Update=20=ED=8C=8C=EC=9D=B4=ED=94=84=20?= =?UTF-8?q?=EC=98=AE=EA=B8=B0=EA=B8=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\230\256\352\270\260\352\270\260.py" | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) 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" index 3ead0cd..5057d20 100644 --- "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" @@ -1,29 +1,35 @@ n = int(input()) +board = [list(map(int, input().split())) for _ in range(n)] -board = [] +# 상태: 가로(0), 세로(1), 대각선(2) +# dp[state][r][c] = 해당 위치에서 가능한 경로 수 +dp = [[[-1] * n for _ in range(n)] for _ in range(3)] -for _ in range(n): - board.append(list(map(int,input().split()))) +def move_pipe(state, r, c): + # 끝에 도달하면 1 + if r == n - 1 and c == n - 1: + return 1 -answer = 0 + # 이미 계산된 경로라면 재사용 + if dp[state][r][c] != -1: + return dp[state][r][c] -def move_pipe(state,r,c): - global answer + total = 0 - if r == n-1 and c == n-1: - answer+=1 - return + # 가로 이동 + if state != 1 and c + 1 < n and board[r][c + 1] == 0: + total += move_pipe(0, r, c + 1) - can_move_h = c + 1 < n and board[r][c+1] == 0 - can_move_v = r + 1 < n and board[r+1][c] == 0 + # 세로 이동 + if state != 0 and r + 1 < n and board[r + 1][c] == 0: + total += move_pipe(1, r + 1, c) - if state != 1 and can_move_h: - move_pipe(0, r, c + 1) - if state != 0 and can_move_v: - move_pipe(1, r+1, c) - if c + 1 < n and r + 1 < n : - if board[r][c+1] == 0 and board[r+1][c] == 0 and board[r+1][c+1] == 0: - move_pipe(2, r + 1, c + 1) + # 대각선 이동 + 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) -move_pipe(0,0,1) -print(answer) \ No newline at end of file + dp[state][r][c] = total + return total + +print(move_pipe(0, 0, 1)) \ No newline at end of file