You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
764 B

#include <bits/stdc++.h>
using namespace std;
//多重背包的裸题,模板一上就解决了,水!
const int N = 1001;
int f[N], v[N], w[N], s[N]; //体积,价值,个数,三个一维数组,f[N][N]就是一个DP表
int n, m;
int main() {
//输入+输出重定向
freopen("../1303.txt", "r", stdin);
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 = m; j >= v[i]; j--) //倒序循环的方法
for (int k = 0; k * v[i] <= j && k <= s[i]; k++) //多重背包的原始写法
f[j] = max(f[j], f[j - k * v[i]] + k * w[i]);
cout << f[m] << endl;
//关闭文件
fclose(stdin);
return 0;
}