# poj-1042

Gone Fishing
 Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 37233 Accepted: 11574

Description

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 
#include<stdio.h>
#include<string.h>
int main()
{//f为最初钓鱼量，t为到下一个湖的时间，d为单位时间的减少量
int h,n,i,j,c=0,ht,ft[30],ans[30][30],f[30],t[30],d[30];
while(scanf("%d%d",&n,&h)&&n)//n个湖，h个小时
{
if(c!=0)
printf("\n");
c=1;
h*=12;//可用时间，一个小时有12个五分钟，以5分钟为单位
memset(ans,0,sizeof(ans));//初始化
memset(f,0,sizeof(f));
memset(t,0,sizeof(t));
memset(d,0,sizeof(d));
for(i=1; i<=n; i++)//输入数据
scanf("%d",&f[i]);
for(i=1; i<=n; i++)
scanf("%d",&d[i]);
for(i=1; i<n; i++)
scanf("%d",&t[i]);
for(i=1; i<=n; i++)
{
memset(ft,0,sizeof(ft));
for(j=1; j<=i; j++)
ft[j]=f[j];//存储最初钓鱼量
ht=h;
for(j=1; j<i; j++)
ht-=t[j];//把走向下一个湖的时间减去
int k,emp=1;
while(ht>0&&emp<=i)
{
k=1;
for(j=emp; j<=i; j++)
if(ft[j]>ft[k])
k=j;
ans[i][0]+=ft[k];//加上最大的钓鱼量
++ans[i][k];//在这个湖里钓鱼的时间加一次
--ht;//拥有时间减去一次
ft[k]-=d[k];//鱼量减一次
ft[k]=ft[k]>0?ft[k]:0;//如果目前所剩鱼量小于0，赋值为0
for(j=emp; j<=i; j++)
{
if(ft[j]==0)
++emp;//统计有几个湖已经没有鱼
else
break;
}
}
if(ht>0)//如果还有时间就把鱼量加上
ans[i][1]+=ht;
}
int a=1;
for(i=2; i<=n; i++)//寻找最大值
if(ans[i][0]>ans[a][0])
a=i;
for(i=1; i<=n; i++)//输出每个湖所呆的时间
{
printf("%d",ans[a][i]*5);
if(i!=n)
printf(", ");
}
printf("\nNumber of fish expected: %d\n",ans[a][0]);
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120