• HDU 2809 God of War (状压DP)


    God of War

    Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1671    Accepted Submission(s): 647

     

    Problem Description

     

    At 184~280 A.D ,there were many kingdoms in China. Three strongest among them are "Wei", "Shu", "Wu". People call this period as "Three Kingdoms".
    HH is a super "Three Kingdoms" fan, because at this period there were many heroes and exciting stories. Among the heroes HH worships LvBu most.
    LvBu is the God of War and is also intelligent, but his ambition is too big while enemies are too powerful .Many monarchs wanted to kill him.
    At 198 A.D ,CaoCao fought with LvBu at Xuzhou.Though Lvbu is the God of War ,CaoCao had so many generals: Xuchu,DianWei XiahouChun……Facing so many heroes ,could LvBu beat all of them?

    Given the LvBu's ATI, DEF, HP, and enemies’ ATI, DEF,HP, experience (if LvBu killed one of his enemies, he can get that experience ,and if his experience got more than or equal to 100*level,he would level-up and become stronger) and the In_ATI,In_DEF,In_HP(indicating when LvBu levels up,his ability will increase this point).
    Each turn LvBu will choose an enemy to fight. Please help LvBu find a way to beat all of enemies and survive with the max HP.
    Here’s a fight between LvBu and A:
    If LvBu attack A, A will lose Max(1,LvBu's ATI- A's DEF) hp;
    If A survived, he will give LvBu Max(1,A'ATI- LvBu'DEF) injury.
    If LvBu is still alive, repeat it untill someone is dead(hp <= 0).

    LvBu's initial level is 1 and experience is 0,and he can level up many times.

     


    Input

     

    The input contains at most 20 test cases.
    For each case , the first line contains six intergers ,indicating LvBu's ATI,DEF,HP and In_ATI,In_DEF,In_HP.
    The next line gives an interger N(0<N<=20),indicating the number of the enemies .
    Then N lines followed, every line contains the name(the length of each name is no more than 20),ATI,DEF,HP, experience(1<experience<=100).
     

    Output

     

    If LvBu is dead output "Poor LvBu,his period was gone."
    Or output the maximum HP left.

    Sample Input

    100  80  100  5  5  5
    2
    ZhangFei 95  75  100  100 
    XuChu 90  90  100  90
    
    100 75 100 5 5 5
    1
    GuanYu 95 85 100 100
     

    Sample Output

    30
    Poor LvBu,his period was gone.

    题目大意

    吕布去打架,有n个对手,告诉你吕布初始攻击力 防御力 生命值 还有每次升级对于三项属性的增加量 以及n个对手的三项属性 和击败他们所能获得的经验值 每次经验值过100就会升级

    每次战斗时,都是吕布先出手,双方造成的伤害是攻击力减防御力。

    问吕布能否将对手全部击败,如果能就输出最后的最大生命值,否则输出"Poor LvBu,his period was gone."

    题目分析

    状压DP,用二进制代表当前已经击败的敌人,dp[i]代表达到当前状态所能维持的最大血量,每次看这个敌人有没有攻击,没有攻击就和他打,打完看能不能更新dp数组即可。

    #include<bits/stdc++.h>
    
    using namespace std;
    
    struct 
    {
        int ati;
        int def;
        int hp;
        int exp;
    }lvbu[1<<21],a[21];
    
    int inati,indef,inhp,n,i,N,j,nati,ndef,nhp,nexp,att,lose,attime,deftime;
    string str;
    
    int main()
    {
        while(scanf("%d%d%d%d%d%d",&lvbu[0].ati,&lvbu[0].def,&lvbu[0].hp,&inati,&indef,&inhp)!=EOF)
        {
            lvbu[0].exp=0;
            cin>>n;
            for(i=0;i<n;i++)
            {
                cin>>str>>a[i].ati>>a[i].def>>a[i].hp>>a[i].exp;
            }
            N=(1<<n)-1;    //这个地方一定不要写成  1<<n-1  会被解释成 1<<(n-1)的!!! 
            for(i=1;i<=N;i++)
            {
                lvbu[i].hp=0;
            }
            for(i=0;i<=N;i++)
            {
                for(j=0;j<n;j++)
                {
                    if(lvbu[i].hp>0&&(!(i&(1<<j))))      //当前状态还有血并且没有和第j个敌人交战 
                    {
                        att=max(1,lvbu[i].ati-a[j].def);   //吕布一刀砍多少 
                        lose=max(1,a[j].ati-lvbu[i].def);   //敌人一刀砍多少 
                        attime=(a[j].hp+att-1)/att;   //打死敌人需要的次数   向上取整 
                        deftime=(lvbu[i].hp+lose-1)/lose;   //敌人打死吕布需要的次数 
                        if(attime>deftime)
                        continue;
                        nhp=lvbu[i].hp-lose*(attime-1);
                        nexp=lvbu[i].exp+a[j].exp;
                        ndef=lvbu[i].def;
                        nati=lvbu[i].ati; 
                        if(nexp>=100)
                        {
                            nhp+=inhp;
                            ndef+=indef;
                            nati+=inati;
                            nexp-=100;
                        }
                        if(lvbu[i|1<<j].hp<=nhp)
                        {
                            lvbu[i|1<<j].hp=nhp;
                            lvbu[i|1<<j].def=ndef;
                            lvbu[i|1<<j].ati=nati;
                            lvbu[i|1<<j].exp=nexp;
                        }
                    }
                }
            }
            if(lvbu[N].hp)
            cout<<lvbu[N].hp<<endl;
            else
            cout<<"Poor LvBu,his period was gone."<<endl;
        }
    }

     

  • 相关阅读:
    单链表反转
    【华为悦读汇】技术发烧友:M-LAG
    Linux系列—策略路由、ip rule、ip route
    对象存储,为什么那么火?
    关于存储技术的最强入门科普
    OpenStack入门科普,看这一篇就够啦!
    虚拟化技术的本质
    师屎胜于熊便:FCoE iSCSI FC组网PK
    懂了!VMware/KVM/Docker原来是这么回事儿
    集群文件系统是什么
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/11386539.html
Copyright © 2020-2023  润新知