This question is very clear. After reading the question, I will think of a DP question. The question is how to define the State and establish a reasonable dynamic planning equation to solve this problem.
The output of this question is the least time spent when the number of bubbles reaches mm. Therefore, the time permission is less than the number of bubbles to mm. Therefore, we can use a two-dimensional backpack to find the maximum number of girls that can be soaked. this is not difficult. In the future, how can we ensure that the time is the least? My approach is to open another array to record the minimum time spent on I "RMB" and J "RP, update the time array and the maximum number of mm for solving a two-dimensional backpack at the same time, so that the minimum time is guaranteed when the number of bubbles to mm is not reduced.
The Code is as follows:
# Include <cstdlib> # include <cstring> # include <cstdio> # include <algorithm> # define maxn 105 using namespace STD; int N, cash, RP, RMB [maxn], RP [maxn], t [maxn]; int DP [maxn] [maxn]; int TT [maxn] [maxn]; void dp () {memset (DP, 0, sizeof (DP); // records the maximum number of MM memsets (TT, 0, sizeof (TT) that can be soaked )); // The time (INT I = 1; I <= N; ++ I) {for (Int J = cash; j> = RMB [I]; -- j) {for (int K = RP; k> = RP [I]; -- K) {If (DP [J] [k] <DP [J-RMB [I] [k-RP [I] + 1) {DP [J] [k] = DP [J-RMB [I] [k-RP [I] + 1; TT [J] [k] = TT [J-RMB [I] [k-RP [I] + T [I];} else if (DP [J] [k] = DP [J-RMB [I] [k-RP [I] + 1) {TT [J] [k] = min (TT [J] [K], TT [J-RMB [I] [k-RP [I] + T [I]) ;}}} printf ("% d \ n ", TT [Cash] [RP]);} int main () {While (scanf ("% d", & n) = 1) {for (INT I = 1; I <= N; ++ I) {scanf ("% d", & RMB [I], & RP [I], & T [I]);} scanf ("% d", & cash, & RP); DP () ;}return 0 ;}