Fate
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 7363 accepted submission (s): 3398
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
# Include <stdio. h ># include <iostream> # include <algorithm> using namespace STD; int DP [105] [105]; // int A [105], B [105]; int max (int x, int y) {return (x> Y? X: Y) ;}int main () {int I, j, P; int n, m, K, s; int min; while (~ Scanf ("% d", & N, & M, & K, & S) {for (I = 1; I <= K; I ++) scanf ("% d", & A [I], & B [I]); memset (DP, 0, sizeof (DP )); // two-dimensional full backpack for (I = 1; I <= K; I ++) // K monsters {for (j = 1; j <= s; j ++) // The number of monsters {for (P = B [I]; P <= m; P ++) // consumption endurance DP [J] [p] = max (DP [J] [p], DP [J-1] [p-B [I] + A [I]);} If (DP [s] [m] <n) printf ("-1 \ n"); // output-1 else {min = m; for (I = 1; I <= s; I ++) {for (j = m; j> = 0; j --) {If (DP [I] [J] >=n & min> J) // find out the patience min = J when the expected experience is reached ;}} printf ("% d \ n", M-min) ;}} return 0 ;}