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>