- 多重背包问题 II
二进制优化:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int f[10001];
struct node
{int v;int w;
};
int main()
{vector<node>cun;int n,V;cin>>n>>V;for (int i=0;i<n;i++){int v,w,s;cin>>v>>w>>s;for (int j=1;j<=s;j++){s-=j;cun.push_back({j*v,j*w});}if (s>0) cun.push_back({s*v,s*w});}for (auto good:cun)for (int i=V;i>=good.v;i--)f[i] = max(f[i],f[i-good.v]+good.w);cout<<f[V]<<endl;
}