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
| #include <iostream>
using namespace std;
const int N = 12000;
int f[N], cnt, n, m, v[N], w[N];
int main() { cin >> n >> m; for (int i = 1; i <= n; i ++ ) { int a, b, s; scanf("%d%d%d", &a, &b, &s); for (int k = 1; k <= s; k <<= 1) { cnt ++ , v[cnt] = a * k, w[cnt] = b * k; s -= k; } if (s) cnt ++, v[cnt] = a * s, w[cnt] = b * s; }
for (int i = 1; i <= cnt; i ++ ) for (int j = m; j >= v[i]; j -- ) f[j] = max(f[j], f[j - v[i]]+ w[i]);
cout << f[m];
return 0; }
|