许诺 • 26天前
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; struct Block {
int h, a, c;
} blocks[405];
bool cmp(const Block &x, const Block &y) {
return x.a < y.a;
} bool dp[40005]; int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> blocks[i].h >> blocks[i].a >> blocks[i].c;
}
sort(blocks, blocks + n, cmp);
memset(dp, 0, sizeof(dp));
dp[0] = true;
for (int i = 0; i < n; i++) {
int h = blocks[i].h, a = blocks[i].a, c = blocks[i].c;
for (int j = a; j >= h; j--) {
if (dp[j]) continue;
for (int k = 1; k <= c; k++) {
if (j - k * h < 0) break;
if (dp[j - k * h]) {
dp[j] = true;
break;
}
}
}
}
int ans = 0;
for (int j = 40000; j >= 0; j--) {
if (dp[j]) {
ans = j;
break;
}
}
cout << ans << endl;
return 0;
}
评论:
请先登录,才能进行评论