Solving the knapsack problem with user provided input
General


You don't have any comments. I recommend you document what basic blocks of code are doing
I recommend factoring out the parsing and algorithm parts of your code into different functions.
Why prompt the user for the number of input items? You can trivially detect it from the second line input, unless this specifies a different value.
Non-descriptive variable names: What does s contain? What does ans mean?
The itertools crate is super helpful whenever iterators are involved


Input Capture / Parsing


Read in both lines at once: let lines = io::stdin().lock().lines().take(2);
Map over those lines, parsing the integers:


let mut numbers = lines.map(|line| {
    line
    .trim()
    .split(' ')
    .map(|s| s.parse::&lt;i32&gt;().unwrap())
});



Split the first line:


let first_line = numbers.next().unwrap().take(2).collect::&lt;Vec&lt;_&gt;&gt;();
assert_eq!(first_line.len(), 2);

let num_items = first_line[0];
let max_weights = first_line[1];



And grab the items from the second line: let items = numbers.next().unwrap().collect::&lt;Vec&lt;_&gt;&gt;();


Algorithm Part 1 (s)


I'd specify the range as 1..(1 &lt;&lt; num_items) to really make clear that second 1 is being shifted, not the whole range.
Personally, I prefer my tuples to be easily spotted. I'd set the iteration result a variable then use that in the tuple:


.map(|i| {
    let sum = items
        .iter()
        .enumerate()
        .filter(|&amp;(t, _)| (i &gt;&gt; t &amp; 1 == 1))
        .map(|(_, elem)| elem.clone())
        .sum::&lt;i32&gt;();
    (sum, i)
})



It's unclear what .filter(|&amp;(t, _)| (i &gt;&gt; t &amp; 1 == 1)) is doing here, but usually bitwise comparisons can be expressed more clearly with other operations.
Additionally, i and t should probably be renamed to be more clear.
Also, those extra parenthesis around the closure return value should instead be used to group whichever operation takes precedence for clarity of the expression
.map(|(_, elem)| elem.clone()) I think can be replaced with .map(|(_, &amp;elem)| elem)
Recommend returning (i, sum) instead of (sum, i) to better match the pattern of enumerate
Extra parenthesis around the return value in .filter(|&amp;(elem, _)| (elem &gt;= 0))
I think .min_by(|(a, _), (b, _)| a.cmp(&amp;b)) can be replaced with .min_by_key(|(x, _)| x)
Doesn't look like you ever use s.0 so you can ignore it with let (_, s): (i32, i32) = ...
In fact, it doesn't look like you use the i index at all after the first .map(|i| { so you don't need to pass it through the rest of the chain.


Algorithm Part 2 (ans)


You repeat (x &gt;&gt; t &amp; 1 == 1) twice: here and above. Perhaps move it to a clearly-named function?
I'd store the ans.iter().fold(...) in a variable before printing the result. Makes the eventual format string output easier to predict.
Suggest using format! in the fold:


.fold(|out, &amp;num| format!("{}{} ", out, num))



Alternatively, you could use join instead of the fold:


ans.into_iter().map(|x| x.to_string()).collect::&lt;Vec&lt;_&gt;&gt;().join(" ")