题解
2023-08-20 14:35:53
发布于:广东
8阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 510;
const int MAX_M = 6010;
int n, m;
int w[MAX_N], c[MAX_N], n_count[MAX_N];
int dp[MAX_N][MAX_M];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> w[i] >> c[i] >> n_count[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
dp[i][j] = dp[i - 1][j];
for (int k = 1; k <= n_count[i] && k * w[i] <= j; ++k) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - k * w[i]] + k * c[i]);
}
}
}
cout << dp[n][m] << endl;
return 0;
}
这数据点太水了
这里空空如也
有帮助,赞一个