You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func main() {
var m, n int
fmt.Scan(&m, &n)
materialSpaces := make([]int, m)
for i := range materialSpaces {
fmt.Scan(&materialSpaces[i])
}
materialValues := make([]int, m)
for i := range materialValues {
fmt.Scan(&materialValues[i])
}
dp := make([]int, n+1)
for i := 0; i < m; i++ {
for j := n; j >= materialSpaces[i]; j-- {
dp[j] = max(dp[j], dp[j-materialSpaces[i]]+materialValues[i])
}
}
fmt.Println(dp[n])
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
`花了1.7s
The text was updated successfully, but these errors were encountered:
`package main
import "fmt"
func main() {
var m, n int
fmt.Scan(&m, &n)
materialSpaces := make([]int, m)
for i := range materialSpaces {
fmt.Scan(&materialSpaces[i])
}
materialValues := make([]int, m)
for i := range materialValues {
fmt.Scan(&materialValues[i])
}
dp := make([]int, n+1)
for i := 0; i < m; i++ {
for j := n; j >= materialSpaces[i]; j-- {
dp[j] = max(dp[j], dp[j-materialSpaces[i]]+materialValues[i])
}
}
fmt.Println(dp[n])
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
`花了1.7s
The text was updated successfully, but these errors were encountered: