You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hello-algo/codes/go/chapter_greedy/fractional_knapsack_test.go

21 lines
423 B

// File: fractional_knapsack_test.go
// Created Time: 2023-07-23
// Author: Reanon (793584285@qq.com)
package chapter_greedy
import (
"fmt"
"testing"
)
func TestFractionalKnapsack(t *testing.T) {
wgt := []int{10, 20, 30, 40, 50}
val := []int{50, 120, 150, 210, 240}
capacity := 50
// 贪心算法
res := fractionalKnapsack(wgt, val, capacity)
fmt.Println("不超过背包容量的最大物品价值为", res)
}