|
|
|
@ -16,11 +16,13 @@ func MaxValue(capacity uint, books []Book) uint {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
book := books[0]
|
|
|
|
|
return Max(
|
|
|
|
|
book.Value+MaxValue(capacity-book.Weight, books[1:]),
|
|
|
|
|
MaxValue(capacity, books[1:]),
|
|
|
|
|
)
|
|
|
|
|
withBook := book.Value + MaxValue(capacity-book.Weight, books[1:])
|
|
|
|
|
withoutBook := MaxValue(capacity, books[1:])
|
|
|
|
|
if book.Weight > capacity {
|
|
|
|
|
return withoutBook
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Max(withBook, withoutBook)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|