二进制处理多重背包,,,
其实无非就是将物品拆成几组, 每一组的数量都是 \(2^n\) 个, 然后因为二进制可以组成所有情况所以就不会漏解啦
比余数分组的做法不知道简单到哪里去了
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e4 + 10;
const int MAXW = 1e3 + 10;
inline int read(){
char ch = getchar(); int x = 0; bool flag = false;
while(!isdigit(ch)) flag |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return flag ? -x : x;
}
int N, M, C;
int f[MAXN], w[MAXN * 100], v[MAXN * 100];
int main(){
cin>>N>>M>>C;
int n = 0;
for(int i = 1; i <= N; i++) {
int wei = read(), cost = read(), num = read();
for(int j = 1; j <= num; j <<= 1)
w[++n] = j * wei, v[n] = j * cost, num -= j;
if(num) w[++n] = wei * num, v[n] = cost * num;
}
for(int i = 1; i <= n; i++)
for(int j = C; j >= w[i]; --j)
f[j] = max(f[j], f[j - w[i]] + v[i]);
for(int i = 1; i <= M; i++) {
int a = read(), b = read(), c = read();
for(int j = C; j; j--)
for(int k = 0; k <= j; k++)
f[j] = max(f[j], f[j - k] + a * k * k + b * k + c);
}
printf("%d\n", f[C]);
return 0;
}