0/1 knapsack algorithm implementation with possibilities vector The following code uses dynamic approach to solve 0/1 knapsack problem. (I know the maximum profit function I have used is not as good as the one I have defined here and I still am working on that . Are any optimizations possible for the following code?

#include "algorithms.h"

struct Item {
    int index = 1;
    int profit = 1;
    int weight = 1;
    Item() = delete;
    explicit Item(int i, int _profit, int w) {
        index = i;
        profit = _profit;
        weight = w;
    }
    bool operator&lt;(const Item&amp; item) {
        return this-&gt;profit &lt; item.profit;
    }
    bool operator&lt;=(const Item&amp; item) {
        return this-&gt;profit &lt;= item.profit;
    }
    bool operator&gt;(const Item&amp; item) {
        return this-&gt;profit &gt; item.profit;
    }
    bool operator&gt;=(const Item&amp; item) {
        return this-&gt;profit &gt;= item.profit;
    }
    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; out, const Item item) {
        out &lt;&lt; item.index;
        return out;
    }
};

long weight(const std::vector&lt;Item&gt;&amp; item_list, const std::vector&lt;int&gt;&amp; item_switch) {
    long sum = 0;
    for (int i = 0; i &lt; item_switch.size(); i++) {
        sum += item_switch[i] * item_list[i].weight;
    }
    return sum;
}

long profit(const std::vector&lt;Item&gt;&amp; item_list, const std::vector&lt;int&gt;&amp; item_switch) {
    long sum = 0;
    for (int i = 0; i &lt; item_switch.size(); i++) {
        sum += item_switch[i] * item_list[i].profit;
    }
    return sum;
}

void increment(std::vector&lt;int&gt;&amp; vec) {
    auto it_bit = vec.end();
    it_bit--;
    while (*it_bit == 1) {
        *it_bit = 0;
        if (it_bit == vec.begin()) {
            return;
        }
        it_bit--;
    }
    *it_bit = 1;
}

int main() {
    long M = 25;
    Item i1(1, 10, 9);
    Item i2(2, 12, 8);
    Item i3(3, 14, 12);
    Item i4(4, 16, 14);
    std::vector&lt;Item&gt; items = { i1,i2,i3,i4 };
    std::vector&lt;int&gt; enable(4,0);
    std::vector&lt;std::vector&lt;int&gt;&gt; possible;
    for (int i = 1; i &lt;= 16; i++) {
        if (weight(items, enable) &lt;= M) {
            possible.push_back(enable);
        }
        increment(enable);
    }
    long pr = 0;
    for (int i = 0; i &lt; possible.size(); i++) {
        long temp = profit(items, possible[i]);
        if (temp &gt; pr) {
            pr = temp;
        }
    }
    std::cout &lt;&lt; pr;
    return 0;
}


P.S. I did not implement the nice suggestion here regarding creation of objects, as during the assignment submission, I am supposed to make objects at run-time.
Since you declare a three parameter constructor, the default constructor will not be implicitly defined, so it does not need to be explicitly deleted.  There's no real harm in providing a default constructor, since you have initializers for all your members.  Alternatively, since the only constructor you supply requires three parameters that initialize all three members of your class, you do not need to provide initializers for them (although doing so can lead to fewer problems in the future if this is expanded on).

The comparison operators should a be declared as const functions.  The use of this-&gt; in them is not necessary.

The output operator should take item as a reference to avoid making a copy.

The weight and profit functions assume that both provided vectors have the same size.  The size used to end the loop can be stored in a variable to avoid potentially recomputing it every time.

In increment, predecrement should be used for iterators (--it_bit;) to avoid making an unnecessary copy.  Have you considered using reverse iterators here (using vec.rbegin())?

The last for loop in main can use the range-for-loop (e.g. for (auto p: possible)).