Poj 1042 gone fishing

Source: Internet
Author: User

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. 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 shocould 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 has Ds 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 has Ds as long as possible at Lake 2, and soon. insert a blank line
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 question Introduction: There are n lakes. It takes H hours. Start from the first Lake each time. The speed of fishing in each lake is fi/5 minutes, and changes every 5 minutes to fi = (FI-DI ). It takes Ti * 5 minutes from I to I + 1. Ask how many fish can be caught. The time for fishing in each lake.

Method: greedy + enumeration. Calculate the remaining time after the farthest lake I. Start with the largest fishing speed in the lake before I. Constant changes, one to maintain the maximum speed.

# 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] indicates the process of reaching Lake a as far as possible, times of staying at Lake B while (scanf ("% d", & lakes), lakes) {memset (Di, 0, sizeof (DI); memset (time, 0, sizeof (time); memset (sum, 0, sizeof (SUM); // inputscanf ("% 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]) ;}// solvefor (INT I = 0; I <lakes; I ++) {int Total = times * 12; // calculate the time remaining after the farthest Lake reaches 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; // locate the maximum vertex or (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 ", sum [Max]);} return 0 ;}

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.