This is the case where each coin has a limit on the number of coins. It is obviously very convenient to use the primary function.
# Include <cstdio> # include <cstring> # include <cmath> # include <algorithm> # include <climits> # include <string> # include <iostream> # include <map> # include <cstdlib> # include <list> # include <set> # include <queue> # include <stack> using namespace STD; typedef long ll; const int maxn = 1000 + 2*1000 + 5*1000 + 5; int c1 [maxn], C2 [maxn], Lim [3], val [3] = {1, 2, 5}; int main () {While (scanf ("% d", & Lim [0], & Lim [1 ], & Lim [2]), Lim [0] + Lim [1] + Lim [2]) {int maxval = lim [0] + 2 * lim [1] + 5 * lim [2]; memset (C1, 0, sizeof (C1); memset (C2, 0, sizeof (C2); For (INT I = 0; I <= lim [0]; I ++) {c1 [I] = 1 ;} for (INT I = 1; I <3; I ++) {for (Int J = 0; j <= lim [I]; j ++) {for (int K = 0; k + J * val [I] <= maxval; k ++) {c2 [K + J * val [I] + = c1 [k] ;}}for (INT I = 0; I <= maxval; I ++) {c1 [I] = c2 [I]; c2 [I] = 0 ;}} int ans = 0; (INT I = 0; I <= maxval + 10; I ++) if (! C1 [I]) {ans = I; break;} printf ("% d \ n", ANS);} return 0 ;}