日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 2809】 God of War(状压dp)

發布時間:2023/12/10 编程问答 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 2809】 God of War(状压dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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 90100 75 100 5 5 5 1 GuanYu 95 85 100 100

Sample Output

30 Poor LvBu,his period was gone.

?

解題報告:

? ?狀壓dp。

AC代碼:

#include<bits/stdc++.h> 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; int n;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)) {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);}for(int i=1;i<(1<<20)+1;i++)dp[i].hp=0;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);if(e[k].hp%sub==0) time--;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; }

總結:

? ? 注意初始化的時候不能直接把dp給memset了,而應該只初始化hp這個成員變量。?

?

總結

以上是生活随笔為你收集整理的【HDU - 2809】 God of War(状压dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。