๋ฐ์ํ
import Foundation
let T = Int(readLine()!)!
for _ in 0..<T{
let n = Int(readLine()!)!
print(dp(n))
}
func dp(_ n: Int) -> Int {
var cache: [Int] = [1, 2, 4]
guard n > 2 else { return n }
for num in 3...n {
cache.append(cache[num - 3] + cache[num - 2] + cache[num - 1])
}
return cache[n-1]
}
๋ฐ์ํ
'๐ ์ฝํ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฐฑ์ค 1926 ๊ทธ๋ฆผ (0) | 2023.06.01 |
---|---|
[Swift] ๋ฐฑ์ค9375 ํจ์ ์ ์ ํด๋น (0) | 2023.04.14 |
[Swift] ๋ฐฑ์ค 10026 ์ ๋ก์์ฝ (0) | 2023.04.14 |
[Swift] ๋ฐฑ์ค 11399 ATM (0) | 2023.04.12 |
[Swift] ๋ฐฑ์ค2178 ๋ฏธ๋กํ์ (0) | 2023.04.12 |