Multiple backpacks. This question does not require binary optimization. Relatively simple. Because the number of duplicates is very small, less than 10;
Add a method to limit the height of each material. If you use reverse table filling, you only need to enter the table from this height to a small recursion.
In addition, pay attention to sorting, and sort by height restriction from small to large. Otherwise, the answer is incorrect.
# Include <stdio. h> # include <string. h ># include <algorithm> Using STD: sort; const int max_k = 401; const int max_h = 40001; struct HCA {int H, A, C; bool operator <(const HCA & HAC) {return a <HAC. A ;}}; HCA [max_k]; bool TBL [max_h]; inline int max (int A, int B) {return A> B? A: B;} int bagdp (int B) {memset (TBL, 0, sizeof (TBL); TBL [0] = true; For (INT I = 1; I <= B; I ++) {int K = 1; for (; (k <1) <= HCA [I]. c; k <= 1) {for (Int J = HCA [I]. a; j> = HCA [I]. H * k; j --) if (TBL [J-HCA [I]. H * k]) TBL [J] = true;} k = HCA [I]. c-k + 1; for (Int J = HCA [I]. a; j> = HCA [I]. H * k; j --) if (TBL [J-HCA [I]. H * k]) TBL [J] = true;} int I = max_h-1; for (; I> 0 &&! TBL [I]; I --); return I;} int main () {int blocks; scanf ("% d", & blocks); For (INT I = 1; I <= blocks; I ++) {scanf ("% d", & HCA [I]. h, & HCA [I]. a, & HCA [I]. c);} Sort (HCA, HCA + blocks + 1); printf ("% d \ n", bagdp (blocks); Return 0 ;}