1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <bits/stdc++.h> #define _for(i, l, r) for (auto i = (l); i <= (r); ++i) #define _rfor(i, r, l) for (auto i = (r); i >= (l); --i) namespace FastIO { char buf[1 << 21], buf2[1 << 21], a[20], *p1 = buf, *p2 = buf, hh = '\n'; int p, p3 = -1; int getc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++; } void read() {} void print() {} template <typename T, typename... T2> void read(T &x, T2 &...oth) { int f = 0; x = 0; char ch = getc(); while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getc(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getc(); } if (f) x = -x; read(oth...); } void flush() { fwrite(buf2, 1, p3 + 1, stdout), p3 = -1; } template <typename T, typename... T2> void print(T x, T2... oth) { if (p3 > 1 << 20) flush(); if (x < 0) buf2[++p3] = 45, x = -x; do { a[++p] = x % 10 + 48; } while (x /= 10); do { buf2[++p3] = a[p]; } while (--p); buf2[++p3] = hh; print(oth...); } template <typename T> void print_h(T x, char h) { if (p3 > 1 << 20) flush(); if (x < 0) buf2[++p3] = 45, x = -x; do { a[++p] = x % 10 + 48; } while (x /= 10); do { buf2[++p3] = a[p]; } while (--p); buf2[++p3] = h; } void putchar(char a) { buf2[++p3] = a; } } using FastIO::print; using FastIO::print_h; using FastIO::read; const int M = 50 + 5; const int N = 400 + 5; int V, Mass, n; int f[N][N]; struct Food { int v, m, cal; } a[M]; int main() { read(V, Mass, n); _for(i, 1, n) read(a[i].v, a[i].m, a[i].cal); _for(i, 1, n) _rfor(j, V, 0) { if (j >= a[i].v) _rfor(k, Mass, 0) { if (k >= a[i].m) f[j][k] = std::max(f[j][k], f[j - a[i].v][k - a[i].m] + a[i].cal); } } print(f[V][Mass]); ex: FastIO::flush(); return 0; }
|