题解 | #多重背包#

多重背包

https://ac.nowcoder.com/acm/problem/235950

拆成01背包
#include<iostream>
using namespace std;
const int M=2010;
int v[M],w[M],n,T,f[M],vv,ww,x,p=0;
int main(){
    cin>>n>>T;
    for(int i=1;i<n+1;i++){
         cin>>x>>ww>>vv;
        while(x--){
            w[++p]=ww;
            v[p]=vv;
        }
    }
    
    for(int i=1;i<p+1;i++){
        for(int j=T;j>=w[i];j--){
            f[j]=max(f[j],f[j-w[i]]+v[i] );
        }
    }
    
    cout<<f[T];
    
    
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务