GoneFishing

Gone Fishing

John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i = 1,…,n - 1, the number of 5-minute intervals it takes to travel from lake i to lake i + 1 is denoted ti (0 < ti <=192). For example, t3 = 4 means that it takes 20 minutes to travel from lake 3 to lake 4. To help plan his fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi( fi >= 0 ), is known. Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval by a constant rate of di (di >= 0). If the number of fish expected to be caught in an interval is less than or equal to di , there will be no more fish left in the lake in the next interval. To simplify the planning, John assumes that no one else will be fishing at the lakes to affect the number of fish he expects to catch.

Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a multiple of 5.

Input

You will be given a number of cases in the input. Each case starts with a line containing n. This is followed by a line containing h. Next, there is a line of n integers specifying fi (1 <= i <=n), then a line of n integers di (1 <=i <=n), and finally, a line of n - 1 integers ti (1 <=i <=n - 1). Input is terminated by a case in which n = 0.

Output

For each test case, print the number of minutes spent at each lake, separated by commas, for the plan achieving the maximum number of fish expected to be caught (you should print the entire plan on one line even if it exceeds 80 characters). This is followed by a line containing the number of fish expected.
If multiple plans exist, choose the one that spends as long as possible at lake 1, even if no fish are expected to be caught in some intervals. If there is still a tie, choose the one that spends as long as possible at lake 2, and so on. Insert a blank line between cases.

Sample Input

2 
1 
10 1 
2 5 
2 
4 
4 
10 15 20 17 
0 3 4 3 
1 2 3 
4 
4 
10 15 50 30 
0 3 4 3 
1 2 3 
0 

Sample Output

45, 5 
Number of fish expected: 31 

240, 0, 0, 0 
Number of fish expected: 480 

115, 10, 50, 35 
Number of fish expected: 724 

约翰是个垂钓谜,星期天他决定外出钓鱼h小时(1≤h≤16),约翰家附近共有n个池塘(2≤n≤25),这些池塘分布在一条直线上,约翰将这些池塘按离家的距离由近到远编上号,依次为L1,L2,…,Ln,约翰家门外就是第一个池塘,所以他到第一个池塘是不用花时间的。

约翰可以任选若干个池塘由近到远地垂钓,并且在每个池塘他都可以呆上任意长的时间,但呆的时间必须为5分钟的倍数(即5分钟为一个单位时间),已知从池塘Li到池塘Li+1要化去约翰ti个单位时间。每个池塘的上鱼率预先也是已知的,池塘Li在第一个单位时间内能钓到的鱼为Fi(0≤Fi≤100),并且每当他在某一个鱼塘呆上一个单位时间后,该鱼塘单位时间内能钓到的鱼将减少一个常数di(0≤di≤100)。

现在请你编一个程序计算约翰最多能钓到多少鱼。

思路:枚举每个池塘为终点,每次选择能掉到最多的鱼的池塘钓鱼。 输出能掉到最多的鱼的方案即可。

代码:

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
#include<iostream>
#define MAXN 30
using namespace std;
int n,h,fi[MAXN],di[MAXN],ti[MAXN],ans[MAXN][MAXN],ft[MAXN],tw[MAXN];
int main(){
while(cin>>n&&n!=0){
cin>>h;
tw[1] = 0;
h *= 12;
for(int i=1;i<=n;i++) cin>>fi[i];
for(int i=1;i<=n;i++) cin>>di[i];
for(int i=2;i<=n;i++) {
cin>>ti[i];
tw[i] = tw[i-1]+ti[i];
}
memset(ans,0,sizeof(ans));
int ans_index = 1;
for(int end=1;end<=n;end++){
for(int i=1;i<=n;i++) ft[i] = fi[i];
int ht = h;
ht -= tw[end];

int max_index=1,emp_c = 0;
while(ht>0&&emp_c<end){
for(int j=1;j<=end;j++){
if(ft[j]>ft[max_index]){
max_index=j;
}
}
--ht;
ans[end][0]+=ft[max_index];
++ans[end][max_index];
ft[max_index]-=di[max_index];
if(ft[max_index]<=0){
emp_c++;
}
}
if(ht>0) ans[end][1]+=ht;

if(ans[end][0]>ans[ans_index][0]) ans_index=end;
}
cout<<ans[ans_index][1]*5;
for(int i=2;i<=n;i++){
cout<<", "<<ans[ans_index][i]*5;
}
cout<<endl<<"Number of fish expected: "<<ans[ans_index][0]<<endl<<endl;
}
return 0;
}
0%