HDU-4310-hero-status DP

Source: Internet
Author: User

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 ;}

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.