Skip to main content

knapsack_01

Function knapsack_01 

Source
pub fn knapsack_01(
    weights: &[usize],
    values: &[f64],
    capacity: usize,
) -> Result<(f64, Vec<usize>), ErrorsJSL>
Expand description

0/1 knapsack: chooses items (each at most once) maximising total value within capacity. Returns (best value, chosen item indices in increasing order). O(n · capacity) time and memory.