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.
21 lines
426 B
21 lines
426 B
8 months ago
|
// 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)
|
||
|
}
|