Hdu 2809 God of War (State compression in Dynamic Planning)

Source: Internet
Author: User

Question: lub vs. qunxiong, each hero has his own attack power, defensive power, and hp (blood volume). lub is quite special. When he has accumulated experience of 100, he can upgrade .. Add attributes when upgrading.

It is fair to say that each hero takes turns to fight Lu Bu. When Lu Bu kills a hero, he can gain experience and ask whether Lu Bu can kill all the heroes, if possible, find

The maximum remaining blood volume.

Analysis: How has this question been assigned to a Search topic? Ah, how to pruning or timeout ......

It is indeed a bare state compressed DP, And the status is transferred from the bottom up

#include<iostream>#include<algorithm>using namespace std;struct hero{int att,def,hp,lev;int exp;}dp[(1<<20)+1];struct enemy{int att,def,hp,exp;};enemy e[25];int att,def,hp;void init(){for(int i=1;i<(1<<20)+1;i++)dp[i].hp=0;}int main(){char str[25];while(scanf("%d %d %d %d %d %d",&dp[0].att,&dp[0].def,&dp[0].hp,&att,&def,&hp)==6){int n=0;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%s %d %d %d %d",str,&e[i].att,&e[i].def,&e[i].hp,&e[i].exp);init();dp[0].lev=1;dp[0].exp=0;for(int j=0;j<(1<<n)-1;j++){if(dp[j].hp<=0)continue;for(int k=0;k<n;k++){hero temp=dp[j];if((j&(1<<k))!=0)continue;int sub=max(temp.att-e[k].def,1);                int sub1=max(e[k].att-temp.def,1);int time=(e[k].hp/sub)+((e[k].hp%sub==0)?-1:0);temp.hp-=time*sub1;if(temp.hp<=0)continue;temp.exp+=e[k].exp;if(temp.exp>=temp.lev*100){temp.lev++;temp.att+=att;temp.def+=def;temp.hp+=hp;}if(temp.hp>dp[j|(1<<k)].hp)dp[j|(1<<k)]=temp;}}if(dp[(1<<n)-1].hp<=0){puts("Poor LvBu,his period was gone.");continue;}printf("%d\n",dp[(1<<n)-1].hp);}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.