概念
参考完全背包
代码
在完全背包的基础上将值设为预定
#include<iostream>
#include<cmath>
using namespace std;
const int N = 110;
int n,m;
int v[N],w[N],s[N];
int dp[N][N];
int main(){
cin>>n>>m;
for(int i = 1;i<=n;i++)
cin>>v[i]>>w[i]>>s[i];
for(int i = 1;i<=n;i++){
for(int j= 0;j<=m;j++){
for(int k=0;k<=s[i];k++){
if(j>=k*v[i])
dp[i][j] = max(dp[i][j],dp[i-1][j-k*v[i]]+w[i]*k);
}
}
}
cout<<dp[n][m];
}
标签:多重,背包,cout,int,include,dp
From: https://www.cnblogs.com/tsqo/p/16877472.html