package kapitel_13 /** * 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 */ object AuD_13_04_MaxSumList_App extends App { def maxSum(lst: List[Int]): Int = lst match { case Nil => 0 case head :: Nil => head case head :: tail => Math.max(maxEndSum(lst), maxSum(tail)) } def maxEndSum(lst: List[Int]): Int = lst match { case head :: Nil => head case head :: tail => Math.max(head, maxEndSum(tail)+head) } val a = Array(1, -4, 3, 18, 1, -8, 2, -1, 10, -5, -80, 20, 3, -2) println(maxSum(a.toList)) // 25 }