This repository was archived by the owner on Nov 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathB1.cpp
More file actions
208 lines (182 loc) · 6.85 KB
/
Copy pathB1.cpp
File metadata and controls
208 lines (182 loc) · 6.85 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include<bits/stdc++.h>
using namespace std;
int n,m,n2=0;
int a[20][20],mymap[100],name[50];
int kind[50],begin,end;
int max_weight,money0,max_day,money_gain;
int water_weight,water_price;
int food_weight,food_price;
int weather_cost[5][5];
int weather[35];
int num_vi,num_mi;
#define foodmax ((int)(max_weight/food_weight))
#define watermax ((int)(max_weight/water_weight))
#define maxnum (1000000000)
int f[32][20][402][602],ans=-maxnum,ansx,ansy,ansz,ansmoney,max_temp2[602];
ifstream file("data1.txt");
ofstream file2("test.txt");
int main(){
file>>max_weight>>money0>>max_day>>money_gain;
file>>water_weight>>water_price;
file>>food_weight>>food_price;
file>>weather_cost[0][0]>>weather_cost[0][1];
file>>weather_cost[1][0]>>weather_cost[1][1];
file>>weather_cost[2][0]>>weather_cost[2][1];
file>>n>>m;
for (int i=1;i<=m;i++){
int xx,yy;
file>>xx>>yy;
if(mymap[xx]==0){
n2++;
mymap[xx]=n2;
name[n2]=xx;
xx=n2;
}
else xx=mymap[xx];
if(mymap[yy]==0){
n2++;
mymap[yy]=n2;
name[n2]=yy;
yy=n2;
}
else yy=mymap[yy];
a[xx][yy]=a[yy][xx]=1;
}
file>>begin>>end;
begin=mymap[begin];
end=mymap[end];
file>>num_vi;
for(int i=1;i<=num_vi;i++){
int xx;
file>>xx;
kind[mymap[xx]]=1;
}
file>>num_mi;
for(int i=1;i<=num_mi;i++){
int xx;
file>>xx;
kind[mymap[xx]]=2;
}
for(int i=1;i<=max_day;i++){
file>>weather[i];
}
for(int day=max_day;day>=0;day--){
for(int place=1;place<=n;place++){
for(int i=0;i<=foodmax;i++)max_temp2[i]=-maxnum;
int max_temp=-maxnum;
for(int water=watermax;water>=0;water--){
max_temp=max_temp2[foodmax];
max_temp-=water_price*4;
for(int food=foodmax;food>=0;food--){
max_temp-=food_price*4;
max_temp2[food]-=water_price*4;
max_temp=max(max_temp,max_temp2[food]);
max_temp=max(max_temp,-maxnum);
if(day==max_day&&place!=end){f[day][place][water][food]=-maxnum;continue;}
if(food*food_weight+water*water_weight>max_weight){f[day][place][water][food]=-maxnum;continue;}
if(day==max_day){
f[day][place][water][food]=water*water_price+food*food_price;
continue;
}
f[day][place][water][food]=-maxnum;
if(day==0&&money0-water*water_price-food*food_price<0)continue;
if(day==0&&place!=begin)continue;
if(place==end)f[day][place][water][food]=water*water_price+food*food_price;
if((water<weather_cost[weather[day+1]][0] || food<weather_cost[weather[day+1]][1])&&kind[place]!=1)continue;
if(kind[place]==1){
f[day][place][water][food]=max(max_temp,f[day][place][water][food]);
if(water<weather_cost[weather[day+1]][0] || food<weather_cost[weather[day+1]][1])continue;
}
if(kind[place]==2 && water>=3*weather_cost[weather[day+1]][0] && food>=3*weather_cost[weather[day+1]][1]){
f[day][place][water][food]=max(f[day][place][water][food],
f[day+1][place][water-3*weather_cost[weather[day+1]][0]][food-3*weather_cost[weather[day+1]][1]]+2*money_gain);
}
if(weather[day+1]==2){
f[day][place][water][food]=max(f[day][place][water][food],
f[day+1][place][water-weather_cost[2][0]][food-weather_cost[2][1]]);
}
else{
for(int place2=1;place2<=n;place2++){
if(place2==place)
f[day][place][water][food]=max(f[day][place][water][food],
f[day+1][place2][water-weather_cost[weather[day+1]][0]][food-weather_cost[weather[day+1]][1]]);
else if(a[place][place2]==1 &&
water>=2*weather_cost[weather[day+1]][0] && food>=2*weather_cost[weather[day+1]][1])
f[day][place][water][food]=max(f[day][place][water][food],
f[day+1][place2][water-2*weather_cost[weather[day+1]][0]][food-2*weather_cost[weather[day+1]][1]]);
}
}
if(kind[place]==1&&f[day][place][water][food]>max_temp)max_temp=f[day][place][water][food];
if(kind[place]==1)max_temp2[food]=max_temp;
if(day==0&&f[day][place][water][food]>-maxnum/2){
f[day][place][water][food]+=2*(money0-water*water_price-food*food_price);
if(f[day][place][water][food]>ans){
ans=f[day][place][water][food];
ansx=place;
ansy=water;
ansz=food;
}
}
}
}
}
}
cout<<ans/2<<endl;
ansmoney=money0-ansy*water_price-ansz*food_price;
ans-=ansmoney*2;
cout<<"day=0\tplace="<<name[ansx]<<"\twater="<<ansy<<"\tfood="<<ansz<<"\tmoney="<<ansmoney<<endl;
for(int day=1;day<=max_day;day++){
for(int place=1;place<=n;place++){
if(place==ansx && ansy>=weather_cost[weather[day]][0] && ansz>=weather_cost[weather[day]][1]){
if(f[day][place][ansy-weather_cost[weather[day]][0]][ansz-weather_cost[weather[day]][1]]==ans){
ansx=place;
ansy=ansy-weather_cost[weather[day]][0];
ansz=ansz-weather_cost[weather[day]][1];
ans=f[day][ansx][ansy][ansz];
cout<<"day="<<day<<"\tplace="<<name[ansx]<<"\twater="<<ansy<<"\tfood="<<ansz<<"\tmoney="<<ansmoney<<endl;
if(kind[place]!=1)goto xxx;
}
else if(kind[place]==2 && ansy>=3*weather_cost[weather[day]][0] && ansz>=3*weather_cost[weather[day]][1] &&
f[day][place][ansy-3*weather_cost[weather[day]][0]][ansz-3*weather_cost[weather[day]][1]]+money_gain*2==ans){
ansx=place;
ansy=ansy-3*weather_cost[weather[day]][0];
ansz=ansz-3*weather_cost[weather[day]][1];
ans=f[day][ansx][ansy][ansz];
ansmoney+=money_gain;
cout<<"day="<<day<<"\tplace="<<name[ansx]<<"\twater="<<ansy<<"\tfood="<<ansz<<"\tmoney="<<ansmoney<<endl;
if(kind[place]!=1)goto xxx;
}
}
if(a[place][ansx]==1 && ansy>=2*weather_cost[weather[day]][0] && ansz>=2*weather_cost[weather[day]][1]){
if(f[day][place][ansy-2*weather_cost[weather[day]][0]][ansz-2*weather_cost[weather[day]][1]]==ans){
ansx=place;
ansy=ansy-2*weather_cost[weather[day]][0];
ansz=ansz-2*weather_cost[weather[day]][1];
ans=f[day][ansx][ansy][ansz];
cout<<"day="<<day<<"\tplace="<<name[ansx]<<"\twater="<<ansy<<"\tfood="<<ansz<<"\tmoney="<<ansmoney<<endl;
if(kind[place]!=1)goto xxx;
}
}
if(kind[place]==1&&ansx==place){
for(int water=watermax;water>=ansy;water--){
for(int food=foodmax;food>=ansz;food--){
if(food==ansz&&water==ansy)continue;
if(food*food_weight+water*water_weight>max_weight)continue;
if(f[day][ansx][water][food]-(water-ansy)*water_price*4-(food-ansz)*food_price*4==ans){
ansmoney-=(water-ansy)*water_price*2+(food-ansz)*food_price*2;
ansx=place;
ansy=water;
ansz=food;
ans=f[day][ansx][ansy][ansz];
cout<<"day="<<day<<"\tplace="<<name[ansx]<<"\twater="<<ansy<<"\tfood="<<ansz<<"\tmoney="<<ansmoney<<endl;
goto xxx;
}
}
}
}
}
xxx:;
}
ansmoney+=ansy*water_price/2+ansz*food_price/2;
cout<<ansmoney;
}