-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU-mc-1001.cpp
119 lines (110 loc) · 1.92 KB
/
HDU-mc-1001.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
ID: mfs6174
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#define US unsigned
#define MAX 1200000
using namespace std;
ifstream inf("ti.in");
//ofstream ouf("ti.out");
//freopen("ti.i","r",stdin);
const int maxlongint=2147483645;
int i,j,k,t,n,m,la,ld,lh,sm;
int f[MAX];
int gong[30],fang[30],xie[30],e[30];
int zongj[MAX];
string ss;
bool ff[MAX];
US cao[30],st;
int exp[100];
inline int suanji(int e)
{
int i;
for (i=0;i<=5;i++)
if (e>=exp[i]&&e<exp[i+1])
return i;
}
inline int suan(US x,int p,int h)
{
int go,fa,fo,fi,t1,t2,ji,hp;
US t=x;
if (!zongj[x])
for (int i=1;i<=n;i++)
{
zongj[x]+=((t&1))?0:e[i];
t=t>>1;
}
ji=zongj[x]/100;
go=ji*la+gong[0];
fa=ji*ld+fang[0];
hp=h+lh*ji+xie[0];
if (hp<=0||h==-maxlongint)
return -maxlongint;
fo=max(1,go-fang[p]);
fi=max(gong[p]-fa,1);
t1=hp/fi;t2=(xie[p]+fo-1)/fo;
if (hp-(t2-1)*fi<=0)
return -maxlongint;
else
return h-(t2-1)*fi;
}
void dfs(US x)
{
if (ff[x])
return;
ff[x]=true;
if (x==st)
{
f[x]=0;
return;
}
US t=x;
int i;
f[x]=-maxlongint;
for (i=1;i<=n;i++)
if ((~x)&cao[i])
{
t=x|cao[i];
dfs(t);
f[x]=max(f[x],suan(t,i,f[t]));
}
}
int main()
{
for (i=1;i<=6;i++)
exp[i]=exp[i-1]+100*i;
while (cin>>gong[0]>>fang[0]>>xie[0]>>la>>ld>>lh)
{
cin>>n;
sm=0;
for (i=1;i<=n;i++)
{
cin>>ss>>gong[i]>>fang[i]>>xie[i]>>e[i];
sm+=e[i];
}
memset(ff,0,sizeof(ff));
memset(f,0,sizeof(f));
memset(zongj,0,sizeof(zongj));
st=0;
for (i=1;i<=n;i++)
{
cao[i]=1<<(i-1);
st=st|cao[i];
}
dfs((unsigned)0);
if ((f[0]==-maxlongint)||(f[0]+sm/100*lh+xie[0]<=0))
cout<<"Poor LvBu,his period was gone."<<endl;
else
cout<<(f[0]+sm/100*lh+xie[0])<<endl;
}
return 0;
}