hdu 2809 临时保存

来源:互联网 发布:淘宝网良品铺子 编辑:程序博客网 时间:2024/06/05 17:31

第一次碰到:状态压缩DP

学习材料:http://wenku.baidu.com/view/aee323cd0508763231121252.html


题目参考:http://www.cnblogs.com/183zyz/archive/2011/07/29/2121380.html

下面是仿照写的,不对


#include "stdio.h"#define PEP 20#define LOW(x) (x)&(-(x));#define MAX(a, b) ((a)>(b)?(a):(b))typedef struct _Man{int atl, def, hp;int exp;}Man, *pMan;Man man[PEP];int s[PEP+1];Man lv[1<<20];int fight(int ko, int w){int a, b;  //LvBu firsta = man[w].hp / MAX((lv[ko].atl-man[w].def), 1);if(man[w].hp % MAX((lv[ko].atl-man[w].def), 1)) a++;   //???b = lv[ko].hp / MAX((man[w].atl-lv[ko].def), 1);if(lv[ko].hp % MAX((man[w].atl-lv[ko].def), 1)) b++;if(a > b) return -1; // LvBu died...return a-1; //remained hp}int bb(int n){int s = 0;while(n){n >>= 1;s++;}return s;}void main(){int in_atl, in_def, in_hp;int n, i;char who[25];int num, z, t, res;freopen("in.txt", "r", stdin);for(i=0; i<=PEP; i++)s[i] = 1<<i;while(scanf("%d %d %d %d %d %d", &(lv[0].atl), &(lv[0].def), &(lv[0].hp), &in_atl, &in_def, &in_hp)!=EOF){lv[0].exp = 0;scanf("%d", &n);for(i=1; i<=n; i++){getchar();scanf("%s %d %d %d %d", who, &(man[i].atl), &(man[i].def), &(man[i].hp), &(man[i].exp));}for(i=1; i<s[n]; i++){lv[i].hp = -1;z = i;while(z){t = LOW(z); z -= t;if(lv[i-t].hp==-1) continue;res = fight(i-t, bb(t));if(res<0) continue; //die...num = 0;if(lv[i-t].exp/100 < (lv[i-t].exp+man[bb(t)].exp)/100)  //lev upnum = (((lv[i-t].exp+man[bb(t)].exp)/100) - (lv[i-t].exp/100));if(lv[i].hp < lv[i-t].hp-res*MAX(man[bb(t)].atl-lv[i-t].def, 1) + num*in_hp){lv[i].atl = lv[i-t].atl + num*in_atl;lv[i].def = lv[i-t].def + num*in_def;lv[i].hp = lv[i-t].hp-res*MAX(man[bb(t)].atl-lv[i-t].def, 1) + num*in_hp;}}}if(lv[s[n]-1].hp==-1) printf("Poor LvBu,his period was gone.\n");else printf("%d\n",lv[s[n]-1].hp);}}


原创粉丝点击