It is easy to use greed to solve this problem. It directly kills the object with a high output per unit time of the other party.
The Dynamic Programming solution for this question is to compress n enemies into an int number, DP [J] indicates the maximum amount of blood deducted when the number of enemies contained in J is left.
The DP equation is DP [s] = min (DP [S-{bit}] + sumdps [s] * H [bit]), where bits enumerate every bit.
The Code is as follows:
# Include <cstdlib> # include <cstring> # include <cstdio> # include <algorithm> using namespace STD; int DP [1200000], n, H [30], DPS [30], C [1200000], sum [1200000]; // DP [J] represents the minimum volume of blood deducted by enemies with binary digits contained in the remaining J number void DFS (int x, int num, int step, int ToT) {If (step = N) {C [x] = num; sum [x] = tot; return;} DFS (x <1, num, step + 1, TOT); DFS (x <1 | 1, num + 1, step + 1, TOT + DPS [n-step]);} void dp () {int Lim = 1 <n; For (INT I = N -1; I> = 0; -- I) {for (Int J = 0; j <lim-1; ++ J) {If (C [J] = I) {for (int K = 0; k <n; ++ K) {If (! (J & (1 <k) {DP [J] = min (DP [J], DP [j | (1 <k)] + sum [j | (1 <k)] * H [k + 1]) ;}}} printf ("% d \ n ", DP [0]);} int main () {While (scanf ("% d", & n) = 1) {memset (DP, 0x3f, sizeof (DP); For (INT I = 1; I <= N; ++ I) {scanf ("% d", & DPS [I], & H [I]);} DFS (0, 0, 0, 0); DP [(1 <n)-1] = 0; DP ();} return 0 ;}