01背包问题-一维数组-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 := v; j >= vi; 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
}