hdu 2809(状压dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809

思路:简单的状压dp,看代码会更明白。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 struct State{
 8     int ati,def,hp,lev,exp;
 9 }dp[1<<20+2];
10 
11 struct Node{
12     int ati,def,hp,exp;
13 }node[21];
14 
15 int n;
16 int In_ati,In_def,In_hp;
17 char str[22];
18 
19 int main()
20 {
21     while(~scanf("%d%d%d%d%d%d",&dp[0].ati,&dp[0].def,&dp[0].hp,&In_ati,&In_def,&In_hp)){
22         scanf("%d",&n);
23         for(int i=0;i<n;i++){
24             scanf("%s%d%d%d%d",str,&node[i].ati,&node[i].def,&node[i].hp,&node[i].exp);
25         }
26         for(int i=1;i<(1<<20)+2;i++){
27             dp[i].hp=0;
28         }
29         dp[0].lev=1;
30         dp[0].exp=0;
31         for(int state=0;state<(1<<n);state++){
32             if(dp[state].hp<=0)continue;
33             for(int i=0;i<n;i++){
34                 if(state&(1<<i))continue;
35                 State S=dp[state];
36                 int tmp1=max(1,S.ati-node[i].def);
37                 int tmp2=max(1,node[i].ati-S.def);
38                 int t=(node[i].hp/tmp1)+((node[i].hp%tmp1==0)?-1:0);
39                 S.hp-=t*tmp2;
40                 if(S.hp<=0)continue;
41                 S.exp+=node[i].exp;
42                 if(S.exp>=S.lev*100){
43                     S.lev++;
44                     S.ati+=In_ati;
45                     S.def+=In_def;
46                     S.hp+=In_hp;
47                 }
48                 if(S.hp>dp[state|(1<<i)].hp){
49                     dp[state|(1<<i)]=S;
50                 }
51             }
52         }
53         if(dp[(1<<n)-1].hp<=0){
54             puts("Poor LvBu,his period was gone.");
55         }else 
56             printf("%d\n",dp[(1<<n)-1].hp);
57     }
58     return 0;
59 }
60 
61 
62                 
63 
64                 
View Code

 

posted @ 2013-09-10 15:29  ihge2k  阅读(384)  评论(0编辑  收藏  举报