Take each solution as an item
Other sold items are also used as an item.
Just take them to the backpack.
Pay attention to the corresponding number.
Code:
# Include <algorithm> # include <iostream> # include <cstring> # include <cstdlib> # include <cctype> # include <cstdio> # include <locale> # include <map> using namespace STD; const int maxn = 110; struct item {int tot, CST; int num [6];} ITM [maxn]; int S, N, totnum; int num [6], id [1005], req [1005], F [6] [6] [6] [6] [6] [6]; bool USF [1005]; int main () {scanf ("% d", & S); int x = 0, y = 0; For (INT I = 1; I <= s; ++ I) {scanf ("% d ", & ITM [I]. TOT); For (Int J = 1; j <= ITM [I]. TOT; ++ J) {scanf ("% d", & X, & Y); If (! Id [x]) {ID [x] = ++ totnum; num [totnum] = x;} ITM [I]. num [ID [x] = y;} scanf ("% d", & ITM [I]. CST);} scanf ("% d", & N); For (INT I = 1; I <= N; ++ I) {scanf ("% d ", & X); If (! Id [x]) {ID [x] = ++ totnum; num [totnum] = x;} scanf ("% d", & req [ID [x]); ITM [++ S]. num [ID [x] = 1; ITM [s]. TOT = 1; scanf ("% d", & ITM [s]. CST);} memset (F, 0x3f, sizeof (f); F [0] [0] [0] [0] [0] = 0; for (INT I = 1; I <= s; ++ I) {for (int A = ITM [I]. num [1]; A <= req [1]; ++ A) {for (int B = ITM [I]. num [2]; B <= req [2]; ++ B) {for (INT c = ITM [I]. num [3]; C <= req [3]; ++ c) {for (INT d = ITM [I]. num [4]; D <= req [4]; ++ d) {for (int e = ITM [I]. num [5]; e <= req [5]; ++ E) {f [a] [B] [C] [d] [e] = min (F [a] [B] [C] [d] [e], f [A-ITM [I]. num [1] [B-ITM [I]. num [2] [C-ITM [I]. num [3] [D-ITM [I]. num [4] [E-ITM [I]. num [5] + ITM [I]. CST) ;}}}} printf ("% d \ n ", f [req [1] [req [2] [req [3] [req [4] [req [5]); Return 0 ;}
Usaco Training Section 3.3 shopping offers