
#[derive(Debug)]
pub struct Knapsack {
    pub size: usize,
    pub n_items: usize,
    pub items: Vec<Item>,
}

#[derive(Debug)]
pub struct Item {
	pub value: usize,
	pub weight: usize,
}

pub fn knapsack(k: &Knapsack) -> usize {
	let mut weight_to_value = vec![0; k.size];
	for item_index in 0..k.n_items {
		let mut new_weight_to_value = weight_to_value.to_vec();
		let item = &k.items[item_index];
		for weight in 0..k.size {
			if weight >= item.weight {
				let current_value = weight_to_value[weight];
				let new_value = weight_to_value[weight - item.weight] + item.value;
				if new_value > current_value {
					new_weight_to_value[weight] = new_value;
				}
			}
		}
		weight_to_value = new_weight_to_value;
	}

	weight_to_value.pop().unwrap()
}