/** * Beispiel aus * * - Algorithmen und Datenstrukturen für Dummies * - von Andreas Gogol-Döring und Thomas Letschert * - Verlag Wiley-VCH; Oktober 2019 * - Kapitel 13, Dynamisches Programmieren * * @author A. Gogol-Döring, Th. Letschert */ import Foundation struct AuD_13_02_MaxSubSumInc { static func maxsubSumBF(_ a: [Int]) -> Int { var maxSubSum : Int = Int.min for l in 0 ..< a.count { for r in l ..< a.count { var subSum = 0 for i in l ... r { subSum = a[i] + subSum } if subSum > maxSubSum { maxSubSum = subSum } } } return maxSubSum } static let a = [1, -4, 3, 18, 1, -8, 2, -1, 10, -5, -80, 20, 3, -2] static func run () { print(maxsubSumBF(a)) // 25 } }