HDU--2639 -- Bone Collector II--01 backpack
Bone Collector IITime Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2464 Accepted Submission(s): 1295Problem DescriptionThe title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you haven't seen it before,it doesn't matter,I will give you a link:Here is the link:http://acm.hdu.edu.cn/showproblem.php?pid=2602Today we are not desiring the maximum value of bones,but the K-th maximum value of the bones.NOTICE that,we considerate two ways that get the same value of bones are the same.That means,it will be a strictly decreasing sequence from the 1st maximum , 2nd maximum .. to the K-th maximum.If the total number of different values is less than K,just ouput 0. InputThe first line contain a integer T , the number of cases.Followed by T cases , each case three lines , the first line contain two integer N , V, K(N <= 100 , V <= 1000 , K <= 30)representing the number of bones and the volume of his bag and the K we need. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone. OutputOne integer per line representing the K-th maximum of the total value (this number will be less than 231). Sample Input35 10 21 2 3 4 55 4 3 2 15 10 121 2 3 4 55 4 3 2 15 10 161 2 3 4 55 4 3 2 1
Sample Output1220
Question: Give You n pieces of bone information (value and volume), give you a backpack with a volume of V, ask you to find the K largest value of all the values of this back-packed bone
After thinking for half a day, I don't know about Baidu. I still don't know the result after I read the replacement report. I don't know what the bloggers want to say, so I checked the Code against the data, and then I was almost confused.
Resolution, backpack 9: The formula learned inside is
F [x] = max [f [x-v] + w, f [x]). It is necessary to record more data for values with K values, so add one dimension to the array and convert it to f [] []. The second dimension is used to record K pieces of data, which are the largest descending order to K, and then directly use the 01 backpack method, f [x] [1 ~ K] contains only K data ~ K is all processed by the above formula, and the resulting data is 2 * K. Do you understand? F [x] [k] and f [x-v] [k] + w, respectively. Then the data can be recorded with the largest K Records.
In fact, I still don't quite understand this. After verification, I had to come to a conclusion that would not make me feel at ease for a long time. Why can this ensure that all values can be obtained in the results? I won't talk about some of the episodes, check the code!
# Include
# Include
# Include
Using namespace std; int main (void) {int n, v, m, I, j, k, l, t; _ int64 dp [0, 1111] [33], a [2] [33], vol [111], val [111]; scanf ("% d", & t); while (t --&&~ Scanf ("% d", & n, & v, & m) {for (I = 0; I
= Vol [I]; j --) {for (k = 0; k
Summary: this is a new way of writing. for me at least, I have not really understood this practice. I just wrote it down. It is useless to remember it. I need to understand it, please wait for two days until you understand it!