完全背包问题-一维数组-golang
blablabla
golang
package main
import "fmt"
var n, v int //种类,总体积
var vi, wi int //体积, 价值
var value []int //体积
func main(){
fmt.Scanf("%d%d", &n, &v)
value = make([]int, v+1)
for i := 1; i <= n; i++{
fmt.Scanf("%d%d", &vi, &wi)
for j := vi; j <= v; j++{
value[j] = max(value[j], value[j-vi]+wi)
}
}
fmt.Println(value[v])
}
func max(a, b int)int{
if a >b{
return a
}
return b
}