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.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const int N = 110;
|
|
|
|
|
const int M = 10010;
|
|
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
struct Node {
|
|
|
|
|
int s; // 吃掉这块能量石需要花费的时间为s秒
|
|
|
|
|
int e; // 获得e个能量
|
|
|
|
|
int l; // 不吃的话,每秒失去l个能量
|
|
|
|
|
const bool operator<(const Node &b) const {
|
|
|
|
|
return s * b.l < b.s * l; // 结构体对比函数
|
|
|
|
|
}
|
|
|
|
|
} q[N]; // 能量石的数组
|
|
|
|
|
|
|
|
|
|
int f[N][M];
|
|
|
|
|
|
|
|
|
|
int idx; // 输出是第几轮的测试数据
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int T;
|
|
|
|
|
scanf("%d", &T);
|
|
|
|
|
while (T--) {
|
|
|
|
|
scanf("%d", &n);
|
|
|
|
|
int m = 0; // 能量视为体积
|
|
|
|
|
int res = 0; // 记录最大值
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
scanf("%d %d %d", &q[i].s, &q[i].e, &q[i].l);
|
|
|
|
|
m += q[i].s; // 极限容量,做为背包的上限
|
|
|
|
|
}
|
|
|
|
|
// 排序
|
|
|
|
|
sort(q + 1, q + 1 + n);
|
|
|
|
|
// 每次清空状态数组
|
|
|
|
|
memset(f, 0, sizeof f);
|
|
|
|
|
|
|
|
|
|
// 二维01背包
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
int l = q[i].l, s = q[i].s, e = q[i].e;
|
|
|
|
|
for (int j = 0; j <= m; j++) {
|
|
|
|
|
f[i][j] = f[i - 1][j]; // 如果不要物品i
|
|
|
|
|
if (j >= s) // 如果可以要物品i
|
|
|
|
|
f[i][j] = max(f[i - 1][j], f[i - 1][j - s] + max(0, e - (j - s) * l));
|
|
|
|
|
res = max(res, f[i][j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cout << "Case #" << ++idx << ": " << res << endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|