POJ 1042 Gone Fishing

Description

John is going on a fishingtrip. He has h hours available (1 <= h <= 16), and there are n lakes inthe area (2 <= n <= 25) all reachable along a single, one-way road. Johnstarts at lake 1, but he can finish at any lake he wants. He can only travelfrom one lake to the next one, but he does not have to stop at any lake unlesshe wishes to. For each i = 1,...,n - 1, the number of 5-minute intervals ittakes 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 tolake 4. To help plan his fishing trip, John has gathered some information aboutthe lakes. For each lake i, the number of fish expected to be caught in theinitial 5 minutes, denoted fi( fi >= 0 ), is known. Each 5 minutes offishing decreases the number of fish expected to be caught in the next 5-minuteinterval by a constant rate of di (di >= 0). If the number of fish expectedto be caught in an interval is less than or equal to di , there will be no morefish left in the lake in the next interval. To simplify the planning, Johnassumes that no one else will be fishing at the lakes to affect the number offish he expects to catch.
Write a program to help John plan his fishing trip to maximize the number offish expected to be caught. The number of minutes spent at each lake must be amultiple of 5.

Input

You will be given a number ofcases in the input. Each case starts with a line containing n. This is followedby 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, aline of n - 1 integers ti (1 <=i <=n - 1). Input is terminated by a casein which n = 0.

Output

For each test case, print thenumber of minutes spent at each lake, separated by commas, for the planachieving the maximum number of fish expected to be caught (you should printthe entire plan on one line even if it exceeds 80 characters). This is followedby a line containing the number of fish expected.
If multiple plans exist, choose the one that spends as long as possible at lake1, even if no fish are expected to be caught in some intervals. If there isstill a tie, choose the one that spends as long as possible at lake 2, and soon. 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

 

t题目简介:有n个湖,给h个小时。每次从第一个湖开始。在每个湖的钓鱼速度为fi条/5分钟,每隔5分钟速度变化一次,变为fi = (fi-di)。从i到i+1需要ti*5分钟。问最多能钓多少条鱼。在每个湖钓鱼的时间为多少。

方法:贪心+枚举。每次算出到到最远的湖i后剩下的时间。以i之前湖中最大的钓鱼速度开始。不断变化,一保持最大的速度。

#include<stdio.h>
#include<string.h>

int main()
{
	int lakes, times, max, num, temp;
	int fi[30], di[30], ti[30];
	int time[30][30], sum[30];//time[a][b]表示最远达到a湖的过程中,b湖停留的次数
	while(scanf("%d",&lakes),lakes)
	{

		memset(di,0,sizeof(di));
		memset(time,0,sizeof(time));
		memset(sum,0,sizeof(sum));

		//input
		scanf("%d",×);
		
		for(int i = 0;i<lakes;i++)
		{
			scanf("%d",&fi[i]);
		}

		for(int i = 0;i<lakes;i++)
		{
			scanf("%d",&di[i]);
		}

		for(int i = 0;i<lakes - 1;i++)
		{
			scanf("%d",&ti[i]);
		}


		//solve
		for(int i = 0;i<lakes;i++)
		{
			int total = times * 12;

			//算出能够达到的最远的湖后剩下的时间
			for(int j = 0;j<i;j++)
			{
				total -= ti[j];
			}

			for(int j = 0;j<total;j++)
			{
				int a, b;
				a = fi[0];
				b = time[i][0] * di[0];
				max = a - b;

				if(max < 0)
				{
					max = 0;
				}

				num = 0;
				//找到此时最大的fi
				for(int k = 0; k<=i; k++)
				{
					temp = fi[k]-time[i][k]*di[k];
					if(temp < 0)
					{
						temp = 0;
					}
					if(max < temp)
					{
						max  = temp;
						num = k;
					}
				}

				time[i][num]++;
				sum[i] += max;
			}
		}
	
		max = 0;
		for(int i = 1; i<lakes; i++)
		{	
			if(sum[max]<sum[i])
			{
				max = i;
			}
		}

		for(int i = 0; i<lakes - 1;i++)
		{	
			printf("%d, ",time[max][i]*5);	
		}
		printf("%d\n",time[max][lakes - 1]*5);

		printf("Number of fish expected: %d\n\n",sum[max]);
	}
	return 0;
}


 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值