多重背包问题 I

题目入口
转化成01背包

#include 
using namespace std;
const int MAXN=1e3+10;
int w[MAXN];
int v[MAXN];
int dp[MAXN];
int main(){
    int n,V;
    cin>>n>>V;
    int tot=0;
    for(int i=1;i<=n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        int x=1;
        while(c>0){
            if(x>c){
                w[tot]=c*a;
                v[tot]=c*b;
            }
            else{
                w[tot]=x*a;
                v[tot]=x*b;
            }
            c-=x;
            tot++;
            x=x<<1;
        }
    }
    for(int i=0;i=w[i];j--){
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    cout<

你可能感兴趣的:(多重背包问题 I)