Pkuoj1042 gone fishing

Source: Internet
Author: User

 

Gone fishing
 
 
Time limit:2000 ms   Memory limit:32768 K
Total submissions:19098   Accepted:5374

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. 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 instances 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 shocould 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 has Ds 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 has Ds 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 
[Problem solution] All ends from the last lake, so the total distance is the same and can be ignored. The rest, as long as you get the most fish you can catch each time, use the priority queue to achieve greed!
#include<iostream>#include<cstring>#include<queue>using namespace std;struct la {    int restf, lanum;};int f[28], d[28], t[28], lt[28], bestl[28];bool operator < (const la &t1, const la &t2){    if(t1.restf==t2.restf) return t1.lanum>t2.lanum;    return t1.restf<t2.restf;}int main(){    int n, h, i, j, endt, nowt, totlef, bestf;    while(cin>>n && n) {        cin>>h;        h*=12;        for(i=0; i<n; i++) cin>>f[i];        for(i=0; i<n; i++) cin>>d[i];        for(i=1; i<n; i++) cin>>t[i];        t[0]=endt=0;        bestf=-1;        for(i=0; i<n; i++) {            endt+=t[i];            if(endt>h) break;            nowt=h-endt;            priority_queue<la>q;            la x;            for(j=0; j<=i; j++) {                x.restf=f[j]; x.lanum=j;                q.push(x);            }            memset(lt, 0, sizeof(lt));            totlef=0;            while(nowt--) {                x=q.top(); q.pop();                lt[x.lanum]++;                totlef+=x.restf;                x.restf-=d[x.lanum];                if(x.restf<0) x.restf=0;                q.push(x);            }            if(totlef>bestf) {                bestf=totlef;                for(j=0; j<=i; j++) bestl[j]=lt[j];                for(; j<n; j++) bestl[j]=0;            }        }        cout<<bestl[0]*5;        for(i=1; i<n; i++) cout<<", "<<bestl[i]*5;        cout<<endl;        cout<<"Number of fish expected: "<<bestf<<endl<<endl;    }    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.