【HDOJ】2809 God of War

状态DP。

 1 /* 2809 */
 2 #include <iostream>
 3 #include <queue>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <cstdlib>
 7 #include <algorithm>
 8 using namespace std;
 9 
10 #define MAXN 20
11 
12 typedef struct {
13     int a, d, h, e;
14 } hero_t;
15 
16 hero_t hero[MAXN];
17 int dp[1<<MAXN];
18 int exp[1<<MAXN];
19 int mask[MAXN];
20 bool visit[1<<MAXN];
21 char name[25];
22 queue<int> Q;
23 
24 int main() {
25     int n, m, size;
26     int la, ld, lh;
27     int ia, id, ih;
28     int ra, rb, ha, hb;
29     int i, j, k, tmp;
30     int s, ss;
31     int slev, alev, dlev, hlev, sslev;
32     
33     #ifndef ONLINE_JUDGE
34         freopen("data.in", "r", stdin);
35     #endif
36     
37     mask[0] = 1;
38     for (i=1; i<MAXN; ++i)
39         mask[i] = (mask[i-1]<<1);
40     
41     while (scanf("%d%d%d%d%d%d", &la,&ld,&lh, &ia,&id,&ih) != EOF) {
42         scanf("%d", &n);
43         for (i=0; i<n; ++i)
44             scanf("%s %d %d %d %d", name, &hero[i].a,&hero[i].d,&hero[i].h,&hero[i].e);
45         m = 1<<n;
46         memset(dp, 0, sizeof(int)*m);
47         memset(visit, false, sizeof(bool)*m);
48         dp[0] = lh;
49         exp[0] = 0;
50         Q.push(0);
51         visit[0] = true;
52         while (!Q.empty()) {
53             s = Q.front();
54             Q.pop();
55             visit[s] = false;
56             for (i=0; i<n; ++i) {
57                 if (s & mask[i])
58                     continue;
59                 ss = s | mask[i];
60                 // calculate s-state level
61                 slev = exp[s]/100;
62                 alev = la+slev*ia;
63                 dlev = ld+slev*id;
64                 // calculate hurt and round
65                 ha = max(1, alev-hero[i].d);
66                 hb = max(1, hero[i].a-dlev);
67                 ra = (hero[i].h+ha-1)/ha;
68                 rb = (dp[s]+hb-1)/hb;
69                 if (ra > rb)
70                     continue;    // LvBu Lose
71                 exp[ss] = exp[s] + hero[i].e;
72                 sslev = exp[ss]/100;
73                 // calculate new hp
74                 tmp = dp[s] - (ra-1)*hb + (sslev-slev)*ih;
75                 dp[ss] = max(dp[ss], tmp);
76                 if (visit[ss] == false) {
77                     visit[ss] = true;
78                     Q.push(ss);
79                 }
80             }
81         }
82         if (dp[m-1])
83             printf("%d\n", dp[m-1]);
84         else
85             printf("Poor LvBu,his period was gone.\n");
86     }
87     
88     return 0;
89 }

 

posted on 2015-01-23 23:42  Bombe  阅读(176)  评论(0编辑  收藏  举报

导航