20250912 baekjoon
This commit is contained in:
parent
c7c4cfb562
commit
687929c8b1
37
code_study/Baekjoon/swift/17070.swift
Normal file
37
code_study/Baekjoon/swift/17070.swift
Normal file
@ -0,0 +1,37 @@
|
||||
if let N: Int = Int(readLine() ?? "0")
|
||||
{
|
||||
var house: [[Int]] = []
|
||||
house.append(Array(repeating: 1, count: N+1))
|
||||
|
||||
for _ in 1...N {
|
||||
if let line = readLine(),
|
||||
let row: [Int] = [1] + line.split(separator: " ").compactMap({Int($0)}) as? [Int],
|
||||
row.count == N+1
|
||||
{
|
||||
house.append(row)
|
||||
}
|
||||
}
|
||||
|
||||
var dp:[[[Int]]] = Array(repeating: Array(repeating: Array(repeating: 0, count: N+1), count: N+1), count: 3)
|
||||
// dp[dir][y][x], dir: 가로(0) 세로(1) 대각선(2)
|
||||
dp[0][1][2] = 1
|
||||
|
||||
for y in 1...N {
|
||||
for x in 1...N {
|
||||
if x == 2 && y == 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
if house[y][x] == 0 {
|
||||
dp[0][y][x] = dp[0][y][x-1] + dp[2][y][x-1] // 가로
|
||||
dp[1][y][x] = dp[1][y-1][x] + dp[2][y-1][x] // 세로
|
||||
|
||||
if house[y-1][x] == 0 && house[y][x-1] == 0 {
|
||||
dp[2][y][x] = dp[0][y-1][x-1] + dp[1][y-1][x-1] + dp[2][y-1][x-1]
|
||||
} // 대각선
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print(dp[0][N][N] + dp[1][N][N] + dp[2][N][N])
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user