ナップサック問題のブルートフォース実装を作成する必要があります。擬似コードは次のとおりです。
computeMaxProfit(weight_capacity)
max_profit = 0
S = {} // Each element of S is a weight-profit pair.
while true
if the sum of the weights in S <= weight_capacity
if the sum of the profits in S > max_profit
update max_profit
if S contains all items // Then there is no next subset to generate
return max
generate the next subset S
アルゴリズムの実装はかなり簡単ですが、Sのべき集合を生成し、そのべき集合のサブセットをwhileループの各反復にフィードする方法については少しもわかりません。
私の現在の実装では、ペアのリストを使用してアイテムの重量と利益を保持しています。
list< pair<int, int> > weight_profit_pair;
そして、computeMaxProfit関数用にこのリストのべき集合を生成したいと思います。リストのサブセットを生成するためのアルゴリズムはありますか?リストは使用するのに適切なコンテナですか?