Link: Fate
State transition equation:
DP [Ren] [num] = max (DP [Ren-durable value] [num-1] + experience value, DP [Ren] [num])
DP:Experience of killing the number of enemies under the current endurance Ren
Enumerate all types of monsters, durability, and number of monsters
Finally, the duration consumed by enumeration can be increased from small to small.
# Include <iostream> # include <algorithm> # include <cstdio> # include <cstring> # include <cstdlib> const int INF = 1e7; using namespace STD; int DP [105] [105], cost [600] [2]; int max (int x, int y) {If (x> Y) return X; else return y;} int min (int x, int y) {If (x> Y) return y; else return X;} int main () {int n, m, k, s; while (~ Scanf ("% d", & N, & M, & K, & S) {for (INT I = 1; I <= K; I ++) {scanf ("% d", & cost [I] [0], & cost [I] [1]);} memset (DP, 0, sizeof (DP); int I, Ren, num, ANS =-1; for (I = 1; I <= K; I ++) {for (REN = cost [I] [1]; ren <= m; ren ++) {for (num = 1; num <= s; num ++) {If (DP [Ren] [num] <DP [Ren-cost [I] [1] [num-1] + cost [I] [0]) DP [Ren] [num] = DP [Ren-cost [I] [1] [num-1] + cost [I] [0] ;}} for (INT I = 1; I <= m; I ++) {If (DP [I] [s]> = N) {ans = m-I; printf ("% d \ n", ANS); break ;}} if (ANS =-1) printf ("% d \ n", ANS );} return 0 ;}