HDU 2159 FATE (two-dimensional full backpack)

Source: Internet
Author: User

HDU 2159 FATE (two-dimensional full backpack)
Problem Description recently xhd is playing a game called FATE. In order to get the best equipment, xhd is constantly killing monsters. Over time, xhd began to dislike monsters, but had to finish this last level by killing monsters. The problem now is that it still requires n experience to upgrade xhd to the last level. xhd also has m patience. Each time you kill a strange xhd, you will get experience, and reduce the patience. Xhd won't play this game when the level of patience falls below 0 or less. Xhd also said that he only kills s at most. Can he upgrade the last level?
There are multiple groups of Input data. For each group of data, there are four positive integers (n, m, k, s (0 <n, m, k, s <100) in the first line. They indicate the expected experience values, the patience to be retained, the number of strange species, and the maximum number to kill monsters. Next, Enter k rows of data. Input two positive integers a and B (0 <a, B <20) for each row of data. They respectively indicate the experience and patience of killing a strange xhd. (There are countless monsters)
The maximum level of patience that can be retained after the Output is upgraded. If the Output level cannot be upgraded, the Output level is-1.
Sample Input

10 10 1 101 110 10 1 91 19 10 2 101 12 2

Sample Output
0-11

 

I learned a bit about the idea of the great gods.

Train of Thought: this is a typical two-dimensional full backpack question. The experience is stored in the backpack, so the capacity of the backpack is based on patience and the number of monsters to be killed, compare the maximum value of a backpack with the experience required for upgrade, and exit after upgrade.

 

# Include
 
  
# Include
  
   
Using namespace std; struct node {int v, w;} a [105]; int dp [105] [105]; int main () {int n, m, k, s; int x, y, z; while (cin> n> m> k> s) // experience, patience, odd species and maximum kill Species {for (int I = 1; I <= k; ++ I) cin> a [I]. v> a [I]. w; memset (dp, 0, sizeof (dp); for (x = 1; x <= m; x ++) {for (y = 1; y <= k; ++ y) for (z = 1; z <= s; ++ z) {int st = 1; while (st * a [y]. w <= x & st <= z) {dp [x] [z] = max (dp [x-st * a [y]. w] [z-st] + st * a [y]. v, dp [x] [z]); st ++ ;}} if (dp [x] [s] >=n) break;} if (x> m) cout <-1 <
   
    

 

 

 

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.