HDOJ 4310 - Hero 简单的状态压缩DP

             题意:

                      hero每轮攻击消耗某个敌人1滴血...敌人血为1时就挂...每个敌人有血量(HP)和攻击值(DPS)...每一轮hero所去的血为所有存活敌人的攻击和.问hero杀死这些敌人最少需要掉多少的血....

             题解:  

                      这两天被题虐吐...找水题来缓解下...N<=20...果断状态DP水了....听说这题还可以贪心..Orz...


Program:

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<queue>
#include<stack>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define oo 1000000007
#define MAXN 20
#define ll int
using namespace std; 
struct node
{
       int DPSi,HPi; 
}enemy[MAXN];
int N,ans,dp[1<<MAXN];
int count(int x)
{
       int data=0,i;
       for (i=0;i<N;i++)
           if (!(x&(1<<i))) data+=enemy[i].DPSi;
       return data;
}
int main()
{ 
       int i,t,x;
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
       while (~scanf("%d",&N))
       {
               for (i=0;i<N;i++) scanf("%d%d",&enemy[i].DPSi,&enemy[i].HPi);
               memset(dp,0x3f,sizeof(dp));
               dp[0]=0;
               for (t=1;t<(1<<N);t++)
                  for (i=0;i<N;i++)
                    if (t&(1<<i))
                    {
                            x=t^(1<<i); 
                            dp[t]=min(dp[t],dp[x]+enemy[i].HPi*count(x));
                    }        
               printf("%d\n",dp[(1<<N)-1]);            
       }       
       return 0;
} 


你可能感兴趣的:(HDOJ 4310 - Hero 简单的状态压缩DP)