0-1 Knapsack problem - implementation Given a set of items with a weight and a value, this problem gives the subset of items which maximize value so that their combined weights is less or equal than a given maximum weight. This solution runs in \$O(w\cdot n)\$ where \$n\$ is the number of items and \$w\$ is the max weight.

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

impl Item {

    fn new(pvalue: usize, pweight: usize) -&gt; Item { 
        Item { value: pvalue, weight: pweight }
    }
}

#[derive(Debug, Clone)]
struct Info {
    ks_value: usize,
    added_weight: usize,
    included: bool,
}

impl Info {
    fn new(pks_value: usize, padded_weight: usize, pincluded: bool) -&gt; Info{
        Info {
            ks_value: pks_value,
            added_weight: padded_weight,
            included: pincluded,
        }  
    }
}

impl std::cmp::Ord for Info {
    fn cmp(&amp;self, other: &amp;Info) -&gt; std::cmp::Ordering {
        self.ks_value.cmp(&amp;other.ks_value)
    }
}

impl PartialOrd for Info {
    fn partial_cmp(&amp;self, other: &amp;Info) -&gt; Option&lt;std::cmp::Ordering&gt; {
        Some(self.cmp(other))
    }
}

impl PartialEq for Info {
    fn eq(&amp;self, other: &amp;Info) -&gt; bool {
        self.ks_value == other.ks_value
    }
}

impl Eq for Info {}

fn _0_1_knapsack_items&lt;'a&gt;(items: &amp;'a[Item], max_weight: usize, subproblems: &amp;[Vec&lt;Info&gt;]) -&gt; Vec&lt;&amp;'a Item&gt;{
        (1..items.len() + 1).rev()
        .scan(max_weight, |w, i| {
                let sub    = &amp;subproblems[i][*w];
                let result = (i, sub.included);
                *w -= sub.added_weight;
                Some(result)
        })
        .filter(|&amp;(_, inc)| inc)
        .take_while(|&amp;(i, _)| i &gt; 0)
        .map(|(i, _)| &amp;items[i - 1])
        .collect::&lt;Vec&lt;&amp;Item&gt;&gt;()
}

fn _0_1_knapsack&lt;'a&gt;(items: &amp;'a [Item], max_weight: usize) -&gt; Vec&lt;&amp;'a Item&gt;{
    let mut subproblems = vec! [ vec! [ Info::new(0, 0, false);
                                       max_weight + 1 ]; 
                                 items.len() + 1 ];
    for i in 0..items.len() {
        for w in 0..max_weight + 1 { 
            let w_i      = items[i].weight;
            let exc_cost = subproblems[i][w].ks_value;
            subproblems[i + 1][w] = if  w &lt; w_i {
                Info::new(exc_cost, 0, false)
            } 
            else {
                let inc_cost = subproblems[i][w - w_i].ks_value 
                               + items[i].value;
                std::cmp::max(Info::new(exc_cost, 0, false), 
                              Info::new(inc_cost, w_i, true))     
            }
        }
    }
    _0_1_knapsack_items(items, max_weight, &amp;subproblems)
}


fn main() {
    let items = [ Item::new(92, 23),  //1
                  Item::new(57, 31),  //1
                  Item::new(49, 29),  //1
                  Item::new(68, 44),  //1
                  Item::new(60, 53),  //0
                  Item::new(43, 38),  //1
                  Item::new(67, 63),  //0
                  Item::new(84, 85),  //0
                  Item::new(87, 89),  //0
                  Item::new(72, 82) ];//0

    for i in _0_1_knapsack(&amp;items, 165){
        println!("{:?}", i);
    }
}
Check out Rustfmt.
There's a Clippy warning for zero_one_knapsack: explicit lifetimes given in parameter types where they could be elided.
Don't prefix every parameter with p. There's no naming conflict and it adds confusion to everyone that tries to use the API. Especially for variables like padded_weight, where "padded" is another English word!
Introduce a key method to DRY up Ord / PartialEq / Hash implementations.
A leading _ means that item is unused but must be present for some reason; don't call your methods that. Switch to words since identifiers can't start with numbers
Start iteration in zero_one_knapsack_items at 0. This simplifies the logic and shows that take_while can be removed.
This also leads to using iter and enumerate instead of operating on a range.
In turn, this leads to removing the need for indexing into items.
Remove the result temporary variable. It doesn't introduce a useful name and doesn't need to occur in a different temporal location.
There is a filter_map that does two operations in one, but I like the separation of filter and map here. You almost want a scan_map.
There's no need to specify type on collect; it's inferred from the return type of the function.
I'm not a fan of the truncated variable names. Computers don't care about long names, but humans do care about short names. This is especially true when there are overlapping meanings for prefixes like inc (included or inclusive).
Prefer iterating on a slice instead of on a range of numbers. If you need the number, use enumerate; this avoids out-of-bounds checking on each index operation.
Implement Default for your type if there's an appropriate value.
Import Ord and max to make that code a bit cleaner to read.




use std::cmp::{Ord, max};

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

impl Item {
    fn new(value: usize, weight: usize) -&gt; Item {
        Item {
            value: value,
            weight: weight,
        }
    }
}

#[derive(Debug, Clone)]
struct Info {
    ks_value: usize,
    added_weight: usize,
    included: bool,
}

impl Info {
    fn new(ks_value: usize, added_weight: usize, included: bool) -&gt; Info {
        Info {
            ks_value: ks_value,
            added_weight: added_weight,
            included: included,
        }
    }

    fn key(&amp;self) -&gt; usize {
        self.ks_value
    }
}

impl Ord for Info {
    fn cmp(&amp;self, other: &amp;Info) -&gt; std::cmp::Ordering {
        self.key().cmp(&amp;other.key())
    }
}

impl PartialOrd for Info {
    fn partial_cmp(&amp;self, other: &amp;Info) -&gt; Option&lt;std::cmp::Ordering&gt; {
        Some(self.cmp(other))
    }
}

impl PartialEq for Info {
    fn eq(&amp;self, other: &amp;Info) -&gt; bool {
        self.key() == other.key()
    }
}

impl Eq for Info {}

impl Default for Info {
    fn default() -&gt; Info {
        Info::new(0, 0, false)
    }
}

fn zero_one_knapsack_items&lt;'a&gt;(items: &amp;'a [Item],
                               max_weight: usize,
                               subproblems: &amp;[Vec&lt;Info&gt;]) -&gt; Vec&lt;&amp;'a Item&gt;
{
    items.iter().enumerate()
        .rev()
        .scan(max_weight, |w, (i, item)| {
            let subproblem = &amp;subproblems[i+1][*w];
            *w -= subproblem.added_weight;
            Some((item, subproblem.included))
        })
        .filter(|&amp;(_, included)| included)
        .map(|(item, _)| item)
        .collect()
}

fn zero_one_knapsack(items: &amp;[Item], max_weight: usize) -&gt; Vec&lt;&amp;Item&gt; {
    let mut subproblems = vec![vec![Info::default(); max_weight + 1]; items.len() + 1];

    for (i, item) in items.iter().enumerate() {
        for w in 0..max_weight + 1 {
            let w_i = item.weight;
            let exclusive_cost = subproblems[i][w].ks_value;
            subproblems[i + 1][w] = if w &lt; w_i {
                Info::new(exclusive_cost, 0, false)
            } else {
                let inclusive_cost = subproblems[i][w - w_i].ks_value + item.value;
                max(Info::new(exclusive_cost, 0, false),
                    Info::new(inclusive_cost, w_i, true))
            }
        }
    }

    zero_one_knapsack_items(items, max_weight, &amp;subproblems)
}

fn main() {
    let items = [Item::new(92, 23),  // 1
                 Item::new(57, 31),  // 1
                 Item::new(49, 29),  // 1
                 Item::new(68, 44),  // 1
                 Item::new(60, 53),  // 0
                 Item::new(43, 38),  // 1
                 Item::new(67, 63),  // 0
                 Item::new(84, 85),  // 0
                 Item::new(87, 89),  // 0
                 Item::new(72, 82)]; // 0

    for i in zero_one_knapsack(&amp;items, 165) {
        println!("{:?}", i);
    }
}