Hut-1675 Find ah find GF DP

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.