比赛 |
寒假归来,刮刮油 |
评测结果 |
AAAAAAAATAAAAAAAAATA |
题目名称 |
还是“金明的预算方案” |
最终得分 |
90 |
用户昵称 |
Menci |
运行时间 |
4.795 s |
代码语言 |
C++ |
内存使用 |
1.04 MiB |
提交时间 |
2016-02-25 20:44:25 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
const int MAXN = 60;
const int MAXV = 3200;
int n, V, s;
struct Tree {
Tree *children, *next;
int c, w;
int f[MAXV + 1];
Tree() {}
Tree(Tree *parent, int c, int w) : next(parent->children), c(c), w(w) {
memset(f, 0, sizeof(f));
}
void solve() {
for (int v = V; v >= c; v--) f[v] = w;
for (Tree *t = children; t; t = t->next) {
t->solve();
for (int v = V - c; v >= t->c; v--) {
for (int i = t->c; i <= std::min(V - c, v + c); i++) {
f[v + c] = std::max(f[v + c], f[v + c - i] + t->f[i]);
}
}
}
}
} trees[MAXN + 1];
inline void addTree(int id, int parent, int c, int w) {
trees[parent].children = new (&trees[id]) Tree(&trees[parent], c, w);
}
int main() {
freopen("budgetb.in", "r", stdin);
freopen("budgetb.out", "w", stdout);
scanf("%d %d %d", &V, &n, &s);
V /= 10;
for (int i = 0; i < n; i++) {
int c, p, q;
scanf("%d %d %d", &c, &p, &q);
addTree(i + 1, q, c / 10, c * p);
}
trees[0].solve();
printf("%d\n", trees[0].f[V]);
fclose(stdin);
fclose(stdout);
return 0;
}