01 backpack water question hdu3466 -- proud merchants

Source: Internet
Author: User


This is a good question.Cainiao has just learned DP, which completely subverts all my previous ideas. In fact, I did not understand the concept of no aftereffect.

Then I went to kaixinxin and asked the Team Leader: "Captain, the Team Leader. How can I understand the impermanence of returning ??? "

The senior student deeply said to me: "If you do more, you will be"

"Oh" (okay)

Then the senior student added the following sentence: "DP can be used to create a directed acyclic graph ."

I thought to myself: "The captain knows how to build a sister ~~~. "

I went to read the Dag silently.


In order to figure out how to write this question, I tried to write it for thousands of times, but I still didn't solve it... Swollen, how can weak food be broken?


It's also a code pasting Link (so annoying, it doesn't really mean that Q-P should be sorted in ascending order. Even though Daniel says it is ineffective, I can only say: I am not aware of it. I have Mu you, de masia ~)


# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> using namespace STD; int DP [5001]; struct node {int P, Q, v;} p [501]; bool CMP (node X, node y) {return X. q-x.p. q-y.p;} int main () {int n, m; while (CIN> N> m) {for (INT I = 0; I <n; I ++) {scanf ("% d", & P [I]. p, & P [I]. q, & P [I]. v);} Sort (p, p + N, CMP); // The sorting order is the raw 01 memset (DP, 0, sizeof DP ); for (INT I = 0; I <n; I ++) {for (Int J = m; j> = P [I]. q; j --) {DP [J] = max (DP [J], DP [J-P [I]. p] + P [I]. v) ;}} cout <DP [m] <Endl;} return 0 ;}< span style = "color: #66 CCCC;"> </span>




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.