๋ฐ์ํ
๋ฌธ์ ๋งํฌ
https://www.acmicpc.net/problem/14501
๋ด๊ฐ ํผ ์ฝ๋
var n = Int(readLine()!)!
var tp: [[Int]] = []
var dp = Array(repeating: 0, count: 100)
for i in 0..<n {
tp.append(readLine()!.split(separator: " ").map { Int(String($0))! })
}
for i in 0..<n {
if dp[i] > dp[i+1] {
dp[i+1] = dp[i]
}
if dp[i+tp[i][0]] < dp[i] + tp[i][1] {
dp[i+tp[i][0]] = dp[i] + tp[i][1]
}
}
print(dp[n])
๋ฐ์ํ
'Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] (Swift) 14889๋ฒ - ์คํํธ์ ๋งํฌ (DFS-๋ฐฑํธ๋ํน) (0) | 2022.05.23 |
---|---|
[๋ฐฑ์ค] (Swift) 11724๋ฒ - ์ฐ๊ฒฐ ์์์ ๊ฐ์ (DFS ์ฐ์ต) (0) | 2022.05.20 |
[๋ฐฑ์ค] (Swift) 1260๋ฒ - DFS์ BFS (0) | 2022.05.14 |
[๋ฐฑ์ค] (Swift) 1759๋ฒ - ์ํธ ๋ง๋ค๊ธฐ (0) | 2022.05.10 |
[๋ฐฑ์ค] (Swift) 15654๋ฒ - N๊ณผ M (5) (DFS๋ก ํ๊ธฐ!) (0) | 2022.05.04 |