Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
n = int(input())
board = [list(map(int, input().split())) for _ in range(n)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ž…๋ ฅ ๊ฐ„๊ฒฐํ•˜๋„ค์˜ˆ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ ์‹œ๊ฐ„ ์•ˆํ„ฐ์ง€๋˜๊ฐ€์š” ? DFSํ–ˆ์„๋•Œ ์ €๋Š” ํ„ฐ์ ธ์„œ dp์ธ๊ฑธ์•Œ์•˜๋Š”๋ฐ..ใ… ใ… ใ… 

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฌด ์ฝ”๋“œ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค !

struct Pipe {
    var tail: (Int, Int)
    var head: (Int, Int)
    
    var direction: Int {
        if tail.0 == head.0 && tail.1 + 1 == head.1 {
            return 0
        } else if tail.0 + 1 == head.0 && tail.1 == head.1 {
            return 1
        } else {
            return 2
        }
    }
    
    func moved(to newDirection: Int) -> Pipe {
        let (r, c) = head
        let newHead: (Int, Int)
        switch newDirection {
        case 0: newHead = (r, c + 1)
        case 1: newHead = (r + 1, c)
        default: newHead = (r + 1, c + 1)
        }
        return Pipe(tail: head, head: newHead)
    }
}
``` ์œ„ ์ฝ”๋“œ์ฒ˜๋Ÿผ ํŒŒ์ดํ”„๋ฅผ ๊ตฌ์กฐ์ฒด๋กœ ๋‘์‹œ๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?

์ดํ›„ 

```swift
let currentDirection = pipe.direction 

์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ€๋…์„ฑ๋„ ๋†’์•„์งˆ๊บผ๊ฐ™์Šต๋‹ˆ๋‹ค !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ถ”๊ฐ€๋กœ

enum Direction: Int {
    case horizontal = 0, vertical = 1, diagonal = 2
}

``` ์ด๋Ÿฐ์‹์œผ๋กœ๋„ ๊ฐ€๋Šฅํ• ๊ฑฐ๊ฐ™์•„์š” !


# ์ƒํƒœ: ๊ฐ€๋กœ(0), ์„ธ๋กœ(1), ๋Œ€๊ฐ์„ (2)
# dp[state][r][c] = ํ•ด๋‹น ์œ„์น˜์—์„œ ๊ฐ€๋Šฅํ•œ ๊ฒฝ๋กœ ์ˆ˜
dp = [[[-1] * n for _ in range(n)] for _ in range(3)]
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜คํ˜ธ ์ด๋ ‡๊ฒŒ ๋Œ€๊ฐ์„ ๊นŒ์ง€ ์ €์žฅํ•˜์…จ๊ตฐ์š”

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ์™€ Enum์˜ ์กฐํ™”,

switch dir {
        case .horizontal:
            hubo = [(Direction.horizontal, x, y+1), (Direction.diagonal, x+1, y+1)]
        case .vertical:
            hubo = [(Direction.vertical, x+1, y), (Direction.diagonal, x+1, y+1)]
        case .diagonal:
            hubo = [(Direction.horizontal, x, y+1), (Direction.vertical, x+1, y), (Direction.diagonal, x+1, y+1)]
    }
    
    ``` ํ•ด๋‹น ๋ฐฉ์‹ ๋„ˆ๋ฌด ์ข‹์€๊ฑฐ๊ฐ™์•„์š” 
    
๋Œ€๊ฐ์„  ์ €์žฅ ๋ฐฉ์‹์€ DP์—์„œ ๋Œ€๊ฐ์„ ์„ ๋‹ด์„๋• ์–ด๋–ค ๋ฐฉ์‹์ด ์žˆ์„์ง€ ๊ณ ๋ฏผ์„ ๋ชปํ–ˆ์–ด์„œ ์ฝ”๋“œ๋ฅผ ์ฐธ๊ณ ํ–ˆ์—ˆ๋„ค์š” ใ…œใ…œ
    


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))
3 changes: 2 additions & 1 deletion YooGyeongMo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
---