Question: How to minimize the damage to a hero who needs to kill n heroes. Each hero on the opposite side has the attack power (DPS) and blood volume (HP). In turn, you can create a hero each time and drop his blood. Each round, all the active heroes will attack you. The amount of blood you lose is equal to the sum of the attacking power of your hero.
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4310
Medium and moderate difficulty. The State compresses DP, and uses DP [mask] to indicate the minimum HP consumption caused by these enemies when killing the enemies of the mask set. Transfer Equation DP [mask] = min {DP [mask-{I}] + hp_sum [mask] * DPS [I], for all I in mask}
// Use DP [mask] to represent the minimum HP consumption caused by these enemies when the enemies of the mask set are killed. // DP [mask] = min {DP [mask-{I}] + hp_sum [mask] * DPS [I], for all I in mask }# include <cstdio> # include <cmath> int INF, N, DP [1 <20], hp_sum [1 <20]; struct node {int HP, DPS;} p [30]; using namespace STD; # include <algorithm> int main () {While (~ Scanf ("% d", & N) {for (INT I = 0; I <n; I ++) {scanf ("% d ", & P [I]. DPS, & P [I]. HP) ;}inf = (1 <n); DP [0] = 0; For (INT I = 0; I <INF; I ++) {hp_sum [I] = 0; DP [I] = 0; For (Int J = 0; j <n; j ++) {if (I & (1 <j) {hp_sum [I] + = P [J]. HP ;}for (Int J = 0; j <n; j ++) {if (I & (1 <j) {If (DP [I]) DP [I] = min (DP [I-(1 <j)] + hp_sum [I] * P [J]. DPS, DP [I]); else DP [I] = DP [I-(1 <j)] + hp_sum [I] * P [J]. DPS ;}} printf ("% d \ n", DP [(1 <n)-1]);} return 0 ;}