You can use a full backpack or greedy one.
Greedy words:
(1) if it happens to be T, update the maximum hamburger count (that is, the maximum number of A + B ).
(2) If t is not collected, the maximum value of A + B is updated when T-Max is the smallest.
Greedy method (0.024 S ):
# include
# include
# include
# include
using namespace STD; int _ max; int main () {# ifdef test freopen ("input.txt", "r", stdin); # endif int M [2], T; while (scanf ("% d", & M [0], & M [1], & T )! = EOF) {int max1 = 0, max2 = 0, peer = 10000; For (INT I = 0; ++ I) {int sum = T-I * m [0]; If (sum <0) break; int num = sum/M [1]; int mod = sum % m [1]; If (! MoD) {If (max1
I + num) continue; max2 = I + num; peer = mod ;}} if (max1! = 0) printf ("% d \ n", max1); else printf ("% d \ n", max2, peer);} return 0 ;}
DP (0.184 ):
# include
# include
# include
# include
using namespace STD; int DP [10001]; const int INF = 0x3fffffff; int main () {# ifdef test freopen ("input.txt", "r", stdin ); # endif int M [2], T; while (scanf ("% d", & M [0], & M [1], & T )! = EOF) {for (INT I = 1; I <= T; ++ I) DP [I] =-INF; DP [0] = 0; for (INT I = 0; I <2; ++ I) for (Int J = m [I]; j <= T; ++ J) {int T = DP [J-M [I] + 1; if (DP [J]
= 0; -- I) if (DP [I]> = 0) {if (I = T) printf ("% d \ n ", DP [I]); else printf ("% d \ n", DP [I], t-I); break ;}return 0 ;}