题解
2023-08-20 14:26:53
发布于:广东
14阅读
0回复
0点赞
#include <iostream>
using namespace std;
const int MAX_N = 1000;
int weights[MAX_N];
int values[MAX_N];
int quantities[MAX_N];
int main() {
int C, n;
cin >> C >> n;
for (int i = 0; i < n; ++i) {
cin >> weights[i] >> values[i] >> quantities[i];
}
int dp[C + 1] = {0};
for (int i = 0; i < n; ++i) {
int weight = weights[i];
int value = values[i];
int quantity = quantities[i];
for (int j = C; j >= weight; --j) {
for (int k = 1; k <= quantity && k * weight <= j; ++k) {
dp[j] = max(dp[j], dp[j - k * weight] + k * value);
}
}
}
cout << dp[C] << endl;
return 0;
}
这里空空如也
有帮助,赞一个